How to install and configure MySQL and change the root password

How to install and configure MySQL and change the root password

1. Installation

apt-get install mysql-server requires setting an account and 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 --> Installation successful

2. Set up MySQL remote access

1. Edit the mysql configuration file and comment out 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 is: 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 to modify MySQL root password

Method 1: Use the SET PASSWORD command

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

Method 2: Using mysqladmin

  mysqladmin -u root password "newpass"

If the root password has been set, use the following method

 mysqladmin -u root password oldpass "newpass"

Method 3: Use UPDATE to edit the user table directly

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

Summarize

The above is the method of Mysql installation, configuration tuning and root password modification introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL SQL statement performance tuning simple example
  • 10 ways to optimize MySQL performance
  • Two important parameters in Mysql optimization and tuning: table_cache and key_buffer
  • MySQL slow query search and tuning test
  • How to check and tune mysql performance
  • Analyze MySQL replication and tuning principles and methods

<<:  Detailed explanation of using Nginx reverse proxy to solve cross-domain problems

>>:  How to implement a lucky wheel game in WeChat applet

Recommend

How to manage docker through UI

Docker is being used in more and more scenarios. ...

The whole process record of Vue export Excel function

Table of contents 1. Front-end leading process: 2...

JavaScript prototype and prototype chain details

Table of contents 1. prototype (explicit prototyp...

HTML+CSS+JavaScript to achieve list loop scrolling example code

Description: Set a timer to replace the content of...

MySQL 8.0.13 decompression version installation graphic tutorial under Windows

This article shares with you the MySQL 8.0.13 ins...

Implementation of form submission in html

Form submission code 1. Source code analysis <...

CocosCreator Getting Started Tutorial: Network Communication

Network Communication Overview When developing an...

HTML set as homepage and add to favorites_Powernode Java Academy

How to implement the "Set as homepage" ...

React passes parameters in several ways

Table of contents Passing parameters between pare...

Solve the problem of the container showing Exited (0) after docker run

I made a Dockerfile for openresty on centos7 and ...

HTML tutorial, easy to learn HTML language (2)

*******************Introduction to HTML language (...