修改MySQL密码初体验

  |   0 评论   |   0 浏览

背景

新安装了一个MySQL (mariadb 10.0),但是登录不上去。

初体验

停止服务

sudo service mysql stop

以无鉴权模块启动

sudo mysqld_safe --skip-grant-tables &

连接MySQL并修改密码

MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user set password=PASSWORD("hello") where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> UPDATE user SET plugin="";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit

重启服务

sudo service mysql stop  
sudo service mysql start

参考