How to Reset the Root Password 5.5

来源:互联网 发布:cmpp3.0协议java开发 编辑:程序博客网 时间:2024/05/18 17:41

B.5.3.2 How to Reset the Root Password

If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root. However, this is insecure. For instructions on assigning passwords, see Section 2.10.4, “Securing the Initial MySQL Accounts”.

If you know the root password and want to change it, see Section 13.7.1.6, “SET PASSWORD Syntax”.

If you assigned a root password previously but have forgotten it, you can assign a new password. The following sections provide instructions for Windows and Unix and Unix-like systems, as well as generic instructions that apply to any system.

B.5.3.2.1 Resetting the Root Password: Windows Systems

On Windows, use the following procedure to reset the password for the MySQL 'root'@'localhost' account. To change the password for a root account with a different host name part, modify the instructions to use that host name.

  1. Log on to your system as Administrator.

  2. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.

    If your server is not running as a service, you may need to use the Task Manager to force it to stop.

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

    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
  4. Save the file. This example assumes that you name the file C:\mysql-init.txt.

  5. Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.

  6. Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):

    C:\> cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"C:\> mysqld --init-file=C:\\mysql-init.txt

    If you installed MySQL to a different location, adjust the cd command accordingly.

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

    To have server output to appear in the console window rather than in a log file, add the --console option to the mysqld command.

    If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option. For example:

    C:\> mysqld         --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 5.5\\my.ini"         --init-file=C:\\mysql-init.txt

    The appropriate --defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel, then Administrative Tools, thenServices. Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.

  7. After the server has started successfully, delete C:\mysql-init.txt.

You should now be able to connect to the MySQL server as root using the new password. Stop the MySQL server and restart it normally. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.

B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems

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

The instructions assume that you will start the MySQL server from the Unix login account that you normally use for running it. For example, if you run the server using themysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root, but in this case you must start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups. If that happens, you will need to either change the ownership of the files to mysql or remove them.

  1. Log on to your system as the Unix 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 file depend 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 extension of .pid and begins with either mysqld or your system's host name.

    Stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process. Use the actual path name of the .pid file 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 the kill command.

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

    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
  4. Save the file. This example assumes that you name 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 --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.

    Other options may be necessary as well, depending on how you normally start your server. For example, --defaults-file may be needed before --init-file.

  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 it normally.

B.5.3.2.3 Resetting the Root Password: Generic Instructions

The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like 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 SET PASSWORD. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.

  2. Connect to the MySQL server using the mysql client; no password is necessary because the server was started with --skip-grant-tables:

    shell> mysql
  3. In the mysql client, tell the server 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 host name.

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

You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables and --skip-networking options).

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 宝宝出生17天睡眠不安稳怎么办 月子里宝宝睡觉老是睡不安稳怎么办 孕妇晚期咳嗽鼻涕黄咽喉痛怎么办 狗狗流脓鼻涕拉稀没食欲怎么办 孕妇眼睛充血很快就有眼屎怎么办 婴儿的眼睛流泪生眼屎怎么办呀 刚出生的婴儿眼睛有眼屎怎么办 25天的婴儿鼻子有鼻屎不通怎么办 一个月的宝宝好多鼻屎怎么办 隆鼻取线的时候好多鼻屎怎么办 小孩流浓鼻涕怎么办最简单方法 小孩流黄鼻涕怎么办最简单方法 一岁八个月宝宝鼻涕和痰多怎么办 空调铜管过不了预埋管的弯头怎么办 如果朝鲜和韩国打起来中国怎么办 寄信时不知道对方的邮编怎么办 地下钱庄转账后银行户被冻结怎么办 老师遇到素质极差的垃圾学生怎么办 验证码忘了手机号也换了怎么办 手机上的验证码忘了怎么办 进入医联网的验证码忘了怎么办 育碧换电脑了无法同步云存档怎么办 刺客信条起源育碧需要激活码怎么办 电脑连不上网怎么办wifi可以用 电脑登录账号密码错误锁定了怎么办 白色T恤衫上沾上黑色的黄油怎么办 家教遇到成绩好的学生该怎么办 跟越南人离婚孩子中国户口9怎么办 老婆是个越南人至今没户口怎么办 等离子屏z板链接处排线打火怎么办 等离子自动调焊的成形不好怎么办 村里内村道路中间被抢占了怎么办 华为换电池之后卡没反应怎么办 汽车钥匙换电池后没反应怎么办 汽车解锁换电池后没反应怎么办 包裹显示待收件人向海关申报怎么办 在越南签证被公安扣了怎么办 酷派手机收不到验证码怎么办 苹果想把图片上的字盖上怎么办 婴儿自己把眼珠子抠红了怎么办 如果美陆战队员进入台湾那怎么办?