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

相關文章
相關標籤/搜索