1. 删除Mysql 数据库
sudo apt autoremove --purge mysql-server-* sudo apt remove mysql-server sudo apt autoremove mysql-server sudo apt remove mysql-common
2. 安装Mysql
sudo apt-get update #更新包 sudo apt install mysql-server-5.7
查看 MySQL 版本
sudo mysql -V
查看MySQL默认账号和密码
sudo cat /etc/mysql/debian.cnf
sudo mysql_secure_installation
#1 VALIDATE PASSWORD PLUGIN can be used to test passwords... Press y|Y for Yes, any other key for No: N #2 Please set the password for root here... New password: (输入密码) Re-enter new password: (重复输入) #3 By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them... Remove anonymous users? (Press y|Y for Yes, any other key for No) : N #4 Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network... Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N #5 By default, MySQL comes with a database named 'test' that anyone can access... Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N #6 Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
systemctl status mysql.service
sudo cat /etc/mysql/debian.cnf # 查看 Password 后面的密码 mysql -u debian-sys-maint -p #进入 mysql 命令模式 mysql> use mysql; mysql> select user,host,authentication_string from user; mysql> update mysql.user set authentication_string=password('密码') where user='root' and Host ='localhost'; mysql> update user set plugin='mysql_native_password'; mysql> select Host, User, plugin from user; mysql> flush privileges; mysql> quit;
修改配置文件,注释掉bind-address = 127.0.0.1
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf :wq mysql -uroot -p mysql> use mysql; mysql> update user set host='%' where user = 'root'; mysql> flush privileges;
#重启 sudo service mysql restart #查看状态 systemctl status mysql.service