Refer to my previous article
A Quick Guide to Using the MySQL APT Repository - Northern Crescent's Blog - CSDN Blog
The environment of this article is pop os, a branch of ubuntu, and the operation is equivalent to ubuntu
Table of contents
(1), Whether to enable VALIDATE PASSWORD to verify the password strength
(2), enter the server password
(3), whether to delete anonymous users
(4), whether to allow remote login
(5), whether to delete the test database
(6), reload the permission table
7. It is forbidden to start automatically
1. Update source
sudo apt update
2. Search mysql-server
sudo apt search mysql-server
Now we can ensure that we can access the mysql-server of the apt warehouse normally
3. Install mysql-server
sudo apt install mysql-server
4. Configure mysql-server
sudo mysql_secure_installation
(1), Whether to enable VALIDATE PASSWORD to verify the password strength
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?Press y|Y for Yes, any other key for No:
Ensure the security of MySQL server deployment.
Connect to MySQL with an empty password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of passwords
and allows users to set only those passwords that are sufficiently strong.
Would you like to set the VALIDATE PASSWORD component?Press y|Y for yes, any other key for no.
We don't check (if we learn to use it ourselves), choose no
(2), enter the server password
Enter the mysql password and enter it normally
(You must remember the password, it will be more troublesome if you forget it)
Please set the password for root here.
New password:
Re-enter new password:
(3), whether to delete anonymous users
By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.You should remove them before moving into a production environment.Remove anonymous users? (Press y|Y for Yes, any other key for No) :
By default, MySQL comes with an anonymous user.
Allows anyone to log in to MySQL without creating a user account for them.
This is just for testing and to make the installation a little smoother.
You should remove them before going into production.Delete anonymous user? (press y|Y for yes, any other key for no).
We choose Y to delete anonymous users
(4), whether to allow remote login
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
Normally, only root should be allowed to connect from 'localhost'. This ensures that someone cannot guess the root password from the network.
Do not allow root remote login? (press y|Y for yes, any other key for no).
We choose N to allow root remote connection
(5), whether to delete the test database
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
Delete the test database and access to it? (press y|Y for yes, any other key for no).
We choose N, do not delete the test database
(6), reload the permission table
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
Reloading the permissions table will ensure that all changes made so far
will take effect immediately.Reload permissions table now? (press y|Y for yes, any other key for no).
We choose Y Effective immediately
At this point, the configuration is complete
5. Check MySQL server status
MySQL server starts automatically after installation. You can check the status of the MySQL server with the following command:
systemctl status mysql
Use the following command to stop MySQL from running:
service mysql stop
Use the following command to start the MySQL server
service mysql start
Use the following command to restart the MySQL server
service mysql restart
6. Configure remote access
MySQL under Ubuntu only allows local access, and it cannot be connected using the database graphical connection tool;
If you want to access, you need to configure
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
Find the bind-address and modify the value to 0.0.0.0
Or directly comment this one
log in to mysql
sudo mysql -u root -p
create account allow
create user 'root'@'%' identified by '你的密码';
Grant permissions to this user
grant all privileges on *.* to 'root'@'%' with grant option;
Refresh permissions
flush privileges;
exit mysql
quit
Restart the MySQL server
service mysql restart
7. It is forbidden to start automatically
sudo systemctl disable mysql
8. Login to MySQL
log in
sudo mysql -uroot -p
query database
show databases;