ubuntu下mysql安装:
sudo apt-get install mysql-server mysql-client
等待下载完成即可选择[y/n]选择y即可;
安装完成后会提示输入账号密码输入完成即可;
授权和window下一样账号密码以root为例
wei@ubuntu:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
mysql> grant all on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> exit
修改配置文件:
#找到my.cnf 文件
root@ubuntu:/home/wei# whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
root@ubuntu:/home/wei# cd /etc/mysql
root@ubuntu:/etc/mysql# ls
conf.d debian-start my.cnf.fallback mysql.conf.d
debian.cnf my.cnf mysql.cnf
root@ubuntu:/etc/mysql# vi my.cnf
#如果有 bind-address = 127.0.0.1进行注释掉没有进行下一步
wei@ubuntu:/etc/mysql$ ls
conf.d debian-start my.cnf.fallback mysql.conf.d
debian.cnf my.cnf mysql.cnf
wei@ubuntu:/etc/mysql$ cd mysql.conf.d/
wei@ubuntu:/etc/mysql/mysql.conf.d$ ls
mysqld.cnf mysqld_safe_syslog.cnf
wei@ubuntu:/etc/mysql/mysql.conf.d$ vi mysqld.cnf
#将其注释掉 bind-address = 127.0.0.1
#保存文件
#重启mysql
root@ubuntu:/home/wei# sudo /etc/init.d/mysql restart
Restarting mysql (via systemctl): mysql.service.
#查询ip
root@ubuntu:/home/wei# ifconfig
ens33 Link encap:Ethernet HWaddr 00:0c:29:4c:2c:a8
inet addr:192.168.60.128 Bcast:192.168.60.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe4c:2ca8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:21947 errors:0 dropped:0 overruns:0 frame:0
TX packets:10883 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:23672949 (23.6 MB) TX bytes:1101847 (1.1 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:160 errors:0 dropped:0 overruns:0 frame:0
TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:11840 (11.8 KB) TX bytes:11840 (11.8 KB)
root@ubuntu:/home/wei# mysql -uroot -p -h192.168.60.128 -P3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
接下来再window 下测试:
Microsoft Windows [版本 10.0.16299.309]
(c) 2017 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>mysql -uroot -p -h192.168.60.128 -P3306
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
进入MySQL成功。
如果出现:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
sudo chown -R mysql:mysql /var/lib/mysql
systemctl start mysqld
查看初始密码
grep 'temporary password' /var/log/mysqld.log
2018-04-18T06:31:06.476857Z 1 [Note] A temporary password is generated for root@localhost: <9M2:p%B#<fz
#密码就是:<9M2:p%B#<fz
mysql> set password=password("root") ;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.01 sec)
mysql> set password=password("root");
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> set password=password("root");
Query OK, 0 rows affected, 1 warning (0.01 sec)