一、知道原来的myql数据库的root密码;
1、 在终端命令行输入
1
|
mysqladmin -u root -p password "新密码" 回车 ,Enter password: 【输入原来的旧密码】
|
2、 登录mysql系统修改, mysql -uroot -p 回车 Enter password: 【输入原来的密码】
1
2
3
4
5
6
7
|
mysql>use mysql;
mysql> update user set password=password( "新密码" ) where user= 'root' ;
mysql> flush privileges;
mysql> exit;
|
然后使用刚才输入的新密码即可登录。
二、不知道原来的myql的root的密码;
首先,你必须要有操作系统的root权限了。
需要先停止mysql服务,/etc/init.d/mysqld stop
当提示mysql已停止后进行下一步操作
1
|
Shutting down MySQL. SUCCESS!
|
在终端命令行输入
1
|
mysqld_safe --skip-grant-tables & 【登录mysql系统】
|
输入mysql登录mysql系统
1
2
3
4
5
6
7
|
mysql> use mysql;
mysql> UPDATE user SET password=password( "新密码" ) WHERE user= 'root' ; 【密码注意大小写】
mysql> flush privileges;
mysql> exit;
|
重新启动mysql服务
这样新的root密码就设置成功了。
三、修改root登录权限
当你修改好root密码后,很有可能出现这种情况
1
|
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' ( using password: YES)
|
这是因为root登录权限不足,具体修改方法如下
需要先停止mysql服务,/etc/init.d/mysqld stop
当提示mysql已停止后进行下一步操作
1
|
Shutting down MySQL. SUCCESS!
|
在终端命令行输入
1
|
mysqld_safe --skip-grant-tables & 【登录mysql系统】
|
输入mysql登录mysql系统
1
2
3
4
5
6
7
8
9
|
mysql>use mysql;
mysql>update user set host = '%' where user = 'root' ;
mysql> select host, user from user;
mysql> flush privileges;
mysql> exit;
|
然后重新启动mysql服务就可以了。
备注:
如果Mysql的版本是5.7及以上的话update语句如下:
mysql> update user set authentication_string=passworD("test") where user='root';
centos8 修改mysql密码
Linux下mysql升级到8.0版本了,以往mysql5.7设置密码的方法已经失效,故各种查资料找方法,寻到mysql8.0root账号密码修改方法。
(注:很多人卡在了步骤5,此时只需将root原来的密码置空再进行修改即可成功 )
1 安装好mysql8.0后,root账号进mysql发现进不去 mysql -uroot -p
2 进入配置文件 vim /etc/my.cnf 添加代码 skip-grant-tables 即可跳过mysql密码验证进行登录
3 重启mysql systemctl restart mysqld
4 重新登录,密码随便填即可进入
5 此时输入 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码'; 发现修改不了 (注意:密码得复杂点,像123456这样的会提示重新设置复杂的密码)
6 需要先将root密码置空 update user set authentication_string='' where user = 'root';
7 再执行步骤5即可修改成功 如果发现步骤5还是报错 请先执行 flush privileges;
8 FLUSH privileges; 刷新mysql相关系统权限表,退出
9 进入配置文件 vim /etc/my.cnf 将这行注释 skip-grant-tables 前面加#即可注释
10 重新启动mysql,输入刚才设置的密码进入mysql:
密码设置成功!
mysql配置外网访问并允许navicat链接
mysql> use mysql;
mysql> update user set host="%" where user='root';
mysql> update user set host="%" where user='root';
mysql> flush privileges;