[Debugging experience] Ubuntu22.04 installation and configuration MySQL 8.0.34

        This article has a total of 1469 words and the estimated reading time is 5 minutes.

        When installing a new version of MySQL on my computer, I followed some online tutorials and found many errors. Finally, I simply explored and installed the service myself. I also sorted out my notes during the operation and uploaded them in the hope that they can help everyone.

Table of contents

text

InstallMySQL

ConfigureMySQL

login account

Method 1: Log in with default account

Method 2: Direct login

local root user

reset Password

Remote root user

Create new user

Granted permission

Refresh permissions

end


text

This guide mainly guides how to install and configure MySQL 8.0.34 version service under Ubuntu 22.04.3 LTS version.


InstallMySQL

If you only want to build a service environment to meet programming needs, it is not recommended to download the source code or other installation packages from the official website for installation. Execute the following statements directly in the terminal, enter the password and wait for the installation to complete:

sudo apt install mysql-server

Feedback interface:

It's that simple, the basic software package of MySQL is installed.


ConfigureMySQL

MySQL will generally be started by default after installation is complete. If it is found that it is not started, you can start it through the command:

sudo service mysql start

hint:

        Sometimes there may be some minor problems, such as the prompt "Unit mysql.service is masked.", which can be solved by the following instructions:

systemctl unmask mysql.service

There is no feedback information after startup. When the current service startup status is unclear, you can query the status through the following statement:

sudo service mysql status

Correct running status:

Q: Of course, some students may ask at this time: "Does this need to be configured to start up? If I restart the computer, will the service start automatically?"

A: The answer is: "Of course you don't have to go to the trouble of starting the service, because these things have been automatically completed during the installation through apt. This is why I warned everyone before that if you don't understand the whole MySQL installation process, there is no need. Reasons for compiling and installing from source code."

Having said so much, let me expand on the relevant service management instructions of MySQL:

  1. sudo service mysql status # View service status
  2. sudo service mysql start # Start the service
  3. sudo service mysql stop # Stop service
  4. sudo service mysql restart # Restart the service

login account

Method 1: Log in with default account

We can view the user name, password and other information under the debian-sys-maint account by using the following commands (MySQL will automatically incorporate this user, just use the values ​​of the user and password items in the file when logging in): 

sudo cat /etc/mysql/debian.cnf

File information:

Method 2: Direct login

You can log in by executing the statement directly

sudo mysql
local root user

After the installation is complete, we need to change the password of the original root account

reset Password

Use the following statement to complete the password modification, where the uppercase PASSWORD is the password that needs to be modified:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD';

Access is already granted by default, so we can just execute the statement directly. Of course, don’t forget to refresh the permissions and execute the following statement:

FLUSH PRIVILEGES;
Remote root user

If you need to provide login services for remote computers, you need to create another root user. Previously we used localhost to represent local login, while remote was represented by the symbol %.

Create new user
create user 'root'@'%' identified by 'PASSWORD';
Granted permission
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Refresh permissions
FLUSH PRIVILEGES;

Three steps, three instructions, can be executed sequentially to complete the task of creating a remote root user. 

end

For students who are not familiar with SQL commands, you can read this article when you have time.

One Thousand Lines of MySQL Study Notes https://shockerli.net/post/1000-line-mysql-note/

Guess you like

Origin blog.csdn.net/weixin_42839065/article/details/132525010