Home >Database >Mysql Tutorial >Introduction to methods of changing root password and installation and configuration tuning in Mysql

Introduction to methods of changing root password and installation and configuration tuning in Mysql

黄舟
黄舟Original
2017-07-30 14:21:521875browse

This article introduces you to Mysql installation and configuration tuning, and then mentions various methods for changing the root password of MySQL in the article. Friends who need it can refer to it

1. Installation

apt-get install mysql-server You need to set the account password


##

apt-get isntall mysql-client
apt-get libmysqlclient-dev

2.sudo netstat -tap | grep mysql to check whether the installation is successful


root@xyz:~# netstat -tap | grep mysql
tcp6    0   0 [::]:mysql       [::]:*         LISTEN   7510/mysqld -->安装成功

2. Set up mysql remote access

1. Edit In the mysql configuration file, annotate bind-address = 127.0.0.1


vi /etc/mysql/mysql.conf.d/mysqld.cnf

2. Use root to enter the mysql command line and execute the following 2 commands. In the example, mysql Root account password: root


grant all on *.* to root@'%' identified by 'root' with grant option;
flush privileges;

3. Restart mysql


/etc/init.d/mysql restart

3. MySQL Multiple methods to change the root password

Method 1: Use the SET PASSWORD command


  mysql -u root
  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

Method 2: Use mysqladmin

##

  mysqladmin -u root password "newpass"

If root has set a password, use the following method

 mysqladmin -u root password oldpass "newpass"

Method 3: Use UPDATE to directly edit the user table

mysql -u root
  mysql> use mysql;
  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
  mysql> FLUSH PRIVILEGES;
   在丢失root密码的时候,可以这样
   mysqld_safe --skip-grant-tables&
   mysql -u root mysql
   mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
   mysql> FLUSH PRIVILEGES;

Summary

The above is the detailed content of Introduction to methods of changing root password and installation and configuration tuning in Mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn