1. Installation
$ sudo apt update
$ sudo apt install mysql-server
2. Configure mysql
$ sudo mysql_secure_installation
The first is to set the password of the root user:
After successfully setting the root password, there will be a series of security settings:
Remove anonymous users? (Press y|Y for Yes, any other key for No) : n
... skipping.
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) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
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) : y
Success.
All done!
3. Verify the installation of mysql :
$ systemctl status mysql.service
4, using the root command and password to log in to just set the mysql go
1,登进MySQL之后,
$ sudo mysql -uroot –p
2,输入以下语句,进入mysql库:
use mysql
3,更新域属性,'%'表示允许外部访问:
update user set host='%' where user ='root';
4,执行以上语句之后再执行:
FLUSH PRIVILEGES;
5,再执行授权语句:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
Error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_secure_installation
update user set host='localhost' where user ='root'' at line 1
Execute sql:
select user,host,password from mysql.user;
Execute sql:
ALTER USER 'root'@'localhost' IDENTIFIED BY '_huitao';
Refresh
FLUSH PRIVILEGES;
Change parameters:
Note that 8.0 has more variables with "." than 5.7, so setting half of it is not enough
set global validate_password.policy=0;
set global validate_password.length=4;
Then exit and then execute
mysql_secure_installation
update user set plugin="mysql_native_password",authentication_string=password('设置的密码') where user="root";
Refresh permissions
FLUSH PRIVILEGES;
Navica can not connect to the database solution:
1. Use the following statement to view the current encryption mode of MySQL
select host,user,plugin from user;
Look at the first line, the root encryption method is caching_sha2_password.
2. Use the command to modify him to mysql_native_password encryption mode:
update user set plugin='mysql_native_password' where user='root';
Navica connects to the database: