# 查看有没有安装MySQL:
dpkg -l | grep mysql
# 安装MySQL:
apt install mysql-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树正在读取状态信息... 完成将会同时安装下列软件: libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7建议安装: libipc-sharedcache-perl mailx tinyca下列【新】软件包将被安装: libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7升级了 0 个软件包,新安装了 9 个软件包,要卸载 0 个软件包,有 237 个软件包未被升级。需要下载 20.5 MB 的归档。解压缩后会消耗 160 MB 的额外空间。您希望继续执行吗? [Y/n] y安装完成登录
root@ubuntu:~# mysql -u root -p
Enter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu)Copyright (c) 2000, 2019, 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 respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
授权设置密码
mysql> grant all on *.* to root@'%' identified by 'root' with grant option;
Query OK, 0 rows affected, 1 warning (0.81 sec)刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)退出
mysql> exit
Bye重新启动
root@ubuntu:~# systemctl restart mysql远程登录设置
root@ubuntu:~# mysql -u root -p
Enter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu)Copyright (c) 2000, 2019, 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 respectiveowners.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 namesYou can turn off this feature to get a quicker startup with -ADatabase changed
设置host属性
mysql> update user set host = '%' where user = 'root';ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'报错可以忽略,可能已存在通过查询
mysql> select host from user where user='root';
修改配置文件
root@ubuntu:~# sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到bind 127.0.0.1 ::1 这一行将它注释掉
root@ubuntu:~# service mysql restart
完成