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

Detailed process of installing the docker plugin in IntelliJ IDEA (2018 version)

Table of contents 1. Development Environment 2. I...

A brief discussion of 3 new features worth noting in TypeScript 3.7

Table of contents Preface Optional Chaining Nulli...

Example of adding music video to HTML page

1. Video tag Supports automatic playback in Firef...

JavaScript using Ckeditor + Ckfinder file upload case detailed explanation

Table of contents 1. Preparation 2. Decompression...

Learn to deploy microservices with docker in ten minutes

Since its release in 2013, Docker has been widely...

Use pictures to realize personalized underline of hyperlinks

Don't be surprised if you see some kind of und...

Teach you how to build the vue3.0 project architecture step by step

Table of contents Preface: 1. Create a project wi...

Implementing simple tabs with js

Tab selection cards are used very frequently on r...

Common writing examples for MySQL and Oracle batch insert SQL

Table of contents For example: General writing: S...

How to modify mysql permissions to allow hosts to access

Enable remote access rights for mysql By default,...

Detailed summary of MySQL and connection-related timeouts

MySQL and connection related timeouts Preface: To...

Detailed explanation of the loop form item example in Vue

Sometimes we may encounter such a requirement, th...