您的位置:首页 > 数据库 > MySQL

mysql 密码变更变化(2)

2016-05-25 18:14 471 查看
1.    密码重置差异

Mysql 5.7 以后当用户忘记了root 用户的密码,我们一般使用 –skip-grant-table option 来跳过mysq 启动时加载用户密码表到内存中。5.7 版本以前各个mysql 的密码重置大同小异,但是在mysl5.7 以后官方提供了一个全新的方法供我们去修改mysql 的root 密码,但是以前5.6 版本的方法依然适用于mysql5.7

 

On Unix, use the following procedure toreset the password for the MySQL 'root'@'localhost' account. To change thepassword for a root account with a different host name part, modify the instructionsto use that host name.

The instructions assume that you will startthe MySQL server from the Unix login account that you normally use for runningit. For example, if you run the server using the mysql login account, youshould log in a smysql before using the instructions. Alternatively,
you canlog in as root, but in this case you must start mysqld with the --user=mysqloption. If you start the server as root without using --user=mysql, the servermay create root-owned files in the data directory, such as log files, and thesemay cause permission-related
problems for future server startups. If thathappens, you will need to either change the ownership of the files to mysql orremove them.

1.      Log on to your system as theUnix user that the MySQL server runs as (for example, mysql).

 

2. Stop the MySQL server if it is running.Locate the .pid file that contains the server's process ID.

The exact location and name of this filedepend on your distribution, host name, and configuration.

Common locations are /var/lib/mysql/,/var/run/mysqld/, and /usr/local/mysql/data/.

Generally, the file name has an extensionof .pid and begins with either mysqld or your system's host name.

Stop the MySQL server by sending a normalkill (not kill -9) to the mysqld process. Use the Actual path name of the .pidfile in the following command:

shell> kill `cat/mysql-data-directory/host_name.pid`

Use backticks (not forward quotation marks)with the cat command. These cause the output of cat to be substituted into thekill command.

 

3. Create a text file containing thepassword-assignment statement on a single line. Replace the password with thepassword that you want to use.

MySQL 5.7.6 and later:

ALTER USER 'root'@'localhost' IDENTIFIED BY'MyNewPass';

MySQL 5.7.5 and earlier:

SET PASSWORD FOR 'root'@'localhost' =PASSWORD('MyNewPass');

 

4. Save the file. This example names the file /home/me/mysql-init. The file contains the password, so do not save it where it can be read by other users. If you are not logged in as mysql (the user the server runs as), make sure that the file has permissions
that permit mysql to read it.

5. Start the MySQL server with the special
--init-file
option:

shell> mysqld_safe--init-file=/home/me/mysql-init &

The server executes the contents of the file named by the --init-file option at startup, changing the'root'@'localhost' account password.

 

6. After the server has started successfully, delete /home/me/mysql-init.

You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart itnormally.

 

 

Resetting the Root Password:Generic Instructions

The preceding sections provide password-resetting instructions for Windows and Unix systems.

Alternatively, on any platform, you can reset the password using the mysql client (but this approach is less secure):

 

1. Stop the MySQL server if necessary, then restart it with the --skip-grant-tables option.

This enables anyone to connect without a password and with all privileges, and disables account-management statements such as ALTER USER and SET PASSWORD. Because this is insecure, you

might want to use --skip-grant-tables inc on junction with --skip-networking to prevent

remote clients from connecting.

 

2. Connect to the MySQL server using themysql client; no password is necessary because the server

was started with --skip-grant-tables:

shell> mysql

 

2.      In the mysql client, tell theserver to reload the grant tables so that account-management statements work:

 

mysql> FLUSH PRIVILEGES;

 

Then change the 'root'@'localhost' account password. Replace the password with the password

that you want to use. To change the password for a root account with a different host name part,

modify the instructions to use that hostname.

MySQL 5.7.6 and later:

 

mysql> ALTER USER 'root'@'localhost'IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5 and earlier:

Administration-Related Issues

3282

mysql> SET PASSWORD FOR'root'@'localhost' = PASSWORD('MyNewPass');

You should now be able to connect to theMySQL server as root using the new password. Stop the server

and restart it normally (without the--skip-grant-tables and --skip-networking options).

 

 

Mysql 5.7 bin tarbal 初始化:

/bin/mysqld --initialize --basedir=/usr/local/mysql57/mysql-5.7.12-linux-glibc2.5-x86_64/--datadir=/home/mysqldata57
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: