Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Setting of root password after installing MySQL under Linux

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Method 1: the easiest way is to install MySQL, according to the method prompted by the system, use mysqladmin to complete.

Shell > mysqladmin-u root password "newpwd"

Shell > mysqladmin-u root-h host_name password "newpwd"

Double quotation marks after password are not required, but if the password contains spaces or some special symbols, you need to use quotation marks.

If root has already set a password, use the following methods

Shell > mysqladmin-u root password oldpass "newpass"

Method 2: use the SET PASSWORD command in mysql to do this. Note that you must use the PASSWORD () function to encrypt the set newpwd, otherwise the direct = 'newpwd' will not take effect. However, if you use the method to set the password with mysqladmin password or GRANT, you do not need to use the PASSWORD () function, because they have already called the function automatically.

Shell > mysql-u root

Mysql > SET PASSWORD FOR 'root'@'localhost' = PASSWORD (' newpwd')

Mysql > SET PASSWORD FOR 'root'@'host_name' = PASSWORD (' newpwd')

Method 3: set the password directly through the UPDATE user table

Shell > mysql-u root

Mysql > UPDATE mysql.user SET Password = PASSWORD ('newpwd') WHERE User =' root'

Mysql > FLUSH PRIVILEGES

If you forget the root password for mysql, take the following steps to reset it

1. Kill drops all mysql processes

$ps-ef | grep mysql

$kill-9 PID

2. Start mysql with the parameter of-- skip-grant-tables

Shell > mysqld_safe-- skip-grant-tables &

3. Set a new password. You can choose the same two ways.

Method one

Shell > mysqladmin-u root flush-privileges password "newpwd"

Method two

Shell > mysql-u root mysql

Mysql > UPDATE mysql.user SET password=PASSWORD ("newpwd") WHERE User='root'

Mysql > FLUSH PRIVILEGES

4. Stop mysql server and start it in normal mode

5. OK, you can use the newly set password.

After installing mysql using the rpm package, follow these steps to reset the root password:

Start mysql:

# / etc/init.d/mysql start

After starting successfully, check the mysql process information and obtain the installation directory of mysqld_safe (very critical):

# ps-ef | grep-I mysql

Root 3466 10 01:45 pts/1 00:00:00 / bin/sh / usr/bin/mysqld_safe-- datadir=/var/lib/mysql-- pid-file=/var/lib/mysql/BSC.TEST.pid

Mysql 3569 3466 16 01:45 pts/1 00:00:00 / usr/sbin/mysqld-basedir=/usr-datadir=/var/lib/mysql-plugin-dir=/usr/lib64/mysql/plugin-user=mysql-log-error=/var/lib/mysql/BSC.TEST.err-pid-file=/var/lib/mysql/BSC.TEST.pid

Root 3597 3105 0 01:45 pts/1 00:00:00 grep-I mysql

You can see the installation location of mysqld_safe (marked in blue above): / usr/bin/

Then execute the following command to stop mysql:

# / etc/init.d/mysql stop

Start mysql in a secure manner:

# / usr/bin/mysqld_safe-- skip-grant-tables > / dev/null 2 > & 1 &

Wait for 5 seconds, and then execute the following statement:

# / usr/bin/mysql-u root mysql

Note: mysql is the same as the mysql_safe directory: / usr/bin/, this is obtained through the "ps-ef | grep-I mysql" command.

At the "mysql >" prompt, enter:

Mysql > update user set password = Password ('root') where User =' root'

Enter (refresh the table related to the permissions of the MySQL system):

Mysql > flush privileges

Then perform exit exit:

Mysql > exit

After exiting, log in to mysql using the following command to see if it is successful:

# mysql-u root-p

Enter the password when prompted: root

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report