Ubuntu中mysql的安装及基本配置

sudo apt install mysql-server

sudo mysql_secure_installation #基础安全配置

sudo mysql

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’; #使root用户使用密码也可以登录mysql

mysql> FLUSH PRIVILEGES;

mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; #创建名为wordpress的数据库

mysql> GRANT ALL ON wordpress.* TO ‘wordpressuser’@‘localhost’ IDENTIFIED BY ‘password’; #创建wordpressuser用户,赋予其wordpress数据库所有权限,且用户密码为password

运行 mysql_secure_installation 后,设置密码时,如果出现下面错误

 ... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.

需要在执行上面命令之前,先手动设置好密码

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'my-secret-password';

然后再执行操作

另起一个ssh,执行下面命令可以kill mysql_secure_installation

sudo kill $(ps aux | grep mysql_secure_installation | grep -v grep | awk '{print $2}')