mysql_root密码重置

2018-01-13 11:02:49来源:oschina作者:linux之路人点击

分享

需求背景:


当mysql root密码忘记了可以用以下配置,修改密码。


[root@wjh5 ~]# vi /etc/my.cnf #打开mysql配置文件#


[mysqld]


port = 3306


socket = /tmp/mysql.sock


skip-locking


key_buffer_size = 256M


max_allowed_packet = 1M


table_open_cache = 256


sort_buffer_size = 1M


read_buffer_size = 1Mo


read_rnd_buffer_size = 4M


myisam_sort_buffer_size = 64M


thread_cache_size = 8


query_cache_size= 16M


# Try number of CPU's*2 for thread_concurrency


thread_concurrency = 8


skip-grant #新增一行#


[root@wjh5 ~]# service mysqld restart#重启mysql服务#


Shutting down MySQL.. SUCCESS!


Starting MySQL.. SUCCESS!


[root@wjh5 ~]# /usr/local/mysql/bin/mysql -uroot #这样就不需要授权直接进入数据库#


Welcome to the MySQL monitor. Commands end with ; or /g.


Your MySQL connection id is 1


Server version: 5.1.73-log MySQL Community Server (GPL)


Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.


mysql> use mysql; #使用数据库#


Database changed


mysql> update user set password=password('12345678')where user='root'; #设定新的密码#


Query OK, 3 rows affected (0.01 sec)


Rows matched: 3 Changed: 3 Warnings: 0


mysql> flush privileges; #刷新权限,不然不生效,不用重启数据库服务#


Query OK, 0 rows affected (0.01 sec)


mysql> quit #退出#


[root@wjh5 ~]# vi /etc/my.cnf #找开配置文件,把添加的skip-grant这行注释掉#


[root@wjh5 ~]# /etc/init.d/mysqld restart #重启mysql服务#


[root@wjh5 ~]# mysql -uroot #登陆#


ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) #提示让用密码登陆#


[root@wjh5 ~]# mysql -uroot -p12345678 #输入刚修改的密码登陆#

刚安装完mysql,会有一个账号root,密码为空的管理员账户


mysqladmin -uroot password '123456' 给root设置一个密码


mysqladmin -uroot -p123456 password '654321'更改root密码


mysql> use mysql; #使用mysql库#


Database changed


mysql> select * from user where user='root'/G; #查看user表,可以查看用户名,密码和权限信息#


mysql -uroot -p88888888 -e "use mysql;select user,host from user where user='root'"

进入mysql如果输入错误,可以输入/c退出

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台