MYSQL8.0之前
sudo apt-get update
sudo apt purge mysql-*
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove
sudo apt clean
sudo apt-get install mysql-server
sudo apt install mysql-client
sudo apt install libmysqlclient-dev
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 注意:将bind-address = 127.0.0.1 改成 bind-address = 0.0.0.0,同时在下面添加:sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sudo mysql -uroot -proot
grant all privileges on *.* to 'root'@'% ' identified by 'root' with grant option;
exit
sudo /etc/init.d/mysql stop (关闭数据库)
sudo /etc/init.d/mysql start (启动数据库)
MYSQL8.0之后
sudo apt-get update
sudo apt purge mysql-*
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove
sudo apt clean
sudo apt-get install mysql-server
sudo apt install mysql-client
sudo apt install libmysqlclient-dev
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 注意:将bind-address = 127.0.0.1 改成 bind-address = 0.0.0.0
sudo mysql -uroot -proot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password123';
CREATE USER 'root'@'%' IDENTIFIED BY 'password123';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
exit
sudo /etc/init.d/mysql stop (关闭数据库)
sudo /etc/init.d/mysql start (启动数据库)