標籤:mysql使用者密碼 修改、重設、找回
1.登入mysql
1.1單一實例登入
1) mysql 剛裝完mysql無密碼情況下登入
2) mysql–u root 剛裝完mysql無密碼情況下登入
3) mysql–u root –p 標準的dba登入
3) mysql–u root –p ‘密碼’ 無互動登入。一般不用,容易泄漏密碼
登入成功後 提示:mysql>
1.2 多執行個體登入
mysql –u root –S 指定mysql.sock檔案的位置
提示:和單一實例唯一的區別是多執行個體需要指定mysql.sock的位置
2.修改使用者密碼
1.1互動式修改root密碼
[[email protected] ~]# mysqladmin -u root -p password ‘jeck123‘ Enter password: ----->輸入舊密碼
[[email protected] ~]# mysqladmin -u root -p password ‘jeck123‘ -S/usr/local/mysql/tmp/mysql.sock Enter password: ----->輸入舊密碼
注意:若剛裝完mysql,則root密碼為空白,直接斷行符號即可
1.2非互動式修改root密碼
[[email protected] ~]# mysqladmin -uroot -p‘jeck123‘ password ‘123jeck‘
[[email protected] ~]# mysqladmin -uroot -p‘jeck123‘ password ‘123jeck‘-S /usr/local/mysql/tmp/mysql.sock
這種用於非互動式修改密碼,適用於指令碼
1.3在mysql資料庫中修改密碼
方法一:(只能修改當前登入mysql使用者的密碼)
[[email protected] ~]# mysql -uroot -p123jeckWelcometo the MySQL monitor. Commands end with; or \g.YourMySQL connection id is 4Serverversion: 5.1.56-log Source distributionCopyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software,andyou are welcome to modify and redistribute it under the GPL v2 licenseType‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> setpassword=password(‘456jeck‘); Query OK, 0 rows affected (0.00 sec)mysql> flushprivileges;Query OK, 0 rows affected (0.00 sec)mysql> exit
方法二:(可以修改任意使用者的密碼,只要有修改許可權)
[[email protected] ~]# mysql -uroot -p456jeckWelcometo the MySQL monitor. Commands end with; or \g.YourMySQL connection id is 6Serverversion: 5.1.56-log Source distributionCopyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software,andyou are welcome to modify and redistribute it under the GPL v2 licenseType‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> updatemysql.user set password=PASSWORD(‘789jeck‘) where user=‘root‘;Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed:3 Warnings: 0mysql> flushprivileges;Query OK, 0 rows affected (0.00 sec)mysql>
3.找回使用者密碼
3.1關閉mysql
[[email protected]~]# service mysqld stopShuttingdown MySQL. SUCCESS![[email protected] ~]# netstat -lnt | grep mysqld
3.2用mysqld_safe啟動mysql,需要加—skip-grant-tables(忽略授權驗證)
單一實例:
[[email protected]~]# /usr/local/mysql/bin/mysqld_safe--skip-grant-tables & --->加&,使進程在後台運行[1]2864315010315:56:25 mysqld_safe Logging to ‘/usr/local/mysql-5.1.56/data/Mysql.err‘.15010315:56:25 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql-5.1.56/data[[email protected] ~]# mysql -uroot -pEnter password: ---->直接斷行符號,因為已經忽略驗證Welcometo the MySQL monitor. Commands end with; or \g.YourMySQL connection id is 1Serverversion: 5.1.56-log Source distributionCopyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software,andyou are welcome to modify and redistribute it under the GPL v2 licenseType‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> setpassword=password(‘jeck123‘); --->此方法不行ERROR 1290 (HY000): The MySQL server is running with the--skip-grant-tables option so it cannot execute this statementmysql> updatemysql.user set password=PASSWORD(‘jeck123‘) where user=‘root‘; Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed:3 Warnings: 0mysql> flushprivileges;Query OK, 0 rows affected (0.00 sec)mysql> exitBye
多執行個體:
[[email protected]~]# /usr/local/mysql/bin/mysqld_safe--defaults-file=/etc/my.cnf --skip-grant-tables &[1]2864315010315:56:25 mysqld_safe Logging to ‘/usr/local/mysql-5.1.56/data/Mysql.err‘.15010315:56:25 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql-5.1.56/data[[email protected] ~]# mysql -uroot -p -S/usr/local/mysql/tmp/mysql.sock Enter password: ---->直接斷行符號,因為已經忽略驗證Welcometo the MySQL monitor. Commands end with; or \g.YourMySQL connection id is 1Serverversion: 5.1.56-log Source distributionCopyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software,andyou are welcome to modify and redistribute it under the GPL v2 licenseType‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> updatemysql.user set password=PASSWORD(‘jeck123‘) where user=‘root‘; ---->修改root密碼 Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed:3 Warnings: 0mysql> flushprivileges;Query OK, 0 rows affected (0.00 sec)mysql> exitBye
3.3重新啟動mysql(必須重新啟動)
[[email protected]~]# service mysqld restartShuttingdown MySQL.150103 16:07:17 mysqld_safe mysqld from pid file/usr/local/mysql-5.1.56/data/Mysql.pid ended SUCCESS! StartingMySQL. SUCCESS! [1]+ Done /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3.4用新修改的密碼就可以登入了
[[email protected]~]# mysql -uroot -pjeck123Welcometo the MySQL monitor. Commands end with; or \g.YourMySQL connection id is 1Serverversion: 5.1.56-log Source distributionCopyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software,andyou are welcome to modify and redistribute it under the GPL v2 licenseType‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>
本文出自 “Study-Everyday” 部落格,請務必保留此出處http://studys.blog.51cto.com/9736817/1599104
mysql關於使用者密碼的設定( 修改、重設、找回)