mysql_root密码重置

需求背景:mysql

当mysql root密码忘记了能够用如下配置,修改密码。sql

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

[mysqld]socket

port = 3306ui

socket = /tmp/mysql.sockspa

skip-lockingrest

key_buffer_size = 256Mip

max_allowed_packet = 1Minput

table_open_cache = 256it

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退出

相关文章
相关标签/搜索