Method of Mysql Installation and Configuration Tuning and Modifying root Password

  • 2021-08-31 09:34:28
  • OfStack

Step 1 Install

apt-get install mysql-server Account password is required


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

2. sudo netstat-tap grep mysql Check to see if the installation was successful


root@xyz:~# netstat -tap | grep mysql
tcp6    0   0 [::]:mysql       [::]:*         LISTEN   7510/mysqld --> Installation succeeded 

2. Set up mysql remote access

1. Edit the mysql configuration file to comment 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 two commands. In the example, the root account password of mysql: root


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

3. Restart mysql


/etc/init.d/mysql restart

3. Various methods of MySQL modifying 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 already set a password, use the following method


   mysqladmin -u root password oldpass "newpass"

Method 3: user table is edited directly with UPDATE


mysql -u root
    mysql> use mysql;
    mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
    mysql> FLUSH PRIVILEGES;
    In the loss root Password, you can do this 
     mysqld_safe --skip-grant-tables&
     mysql -u root mysql
     mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
     mysql> FLUSH PRIVILEGES;

Summarize


Related articles: