Ubuntu install MySQL (Ali cloud server) under

Install the client and depend on the environment

sudo apt install mysql-server #安装mysql服务器端
sudo apt install mysql-client #安装mysql客户端
sudo apt install libmysqlclient-dev #安装服务端/客户端依赖环境(可有可无,建议安装)

Initialization MySQL (MySQL 5.7 has not set a default password, you need to initialize that run the Security Wizard)

sudo mysql_secure_installation

Security Wizard:

1. (random password is set, Y / y random password, N / n own password)

PASSWORD the PLUGIN CAN BE Used VALIDATE to the Test Passwords ...
Press the y-| for the Y-Yes, for the any OTHER Key No: N (my option)
Please the SET at The password for root here Wallpaper ...
New password: (password)
Re- enter new password: (repeat input)

2. (whether to remove the anonymous user, the proposed deletion)

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...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y (我的选项)

3. (whether to prohibit the root account remote login, the proposed ban)

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 (我的选项)

4. (whether to delete the test database, suggested deleting)

By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y (我的选项)

5. (whether to reload the privilege tables, you should reload)

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 (我的选项)

Modify the configuration file (see the specific need for remote access to the database)

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
/bind #查找bind-address,然后注释该行并保存

Restart MySQL service

sudo service mysql restart

From MySQL-Client login MySQL (the first landing an idea log in as root)

mysql -u root -p

## created to remote login user
create user 用户名(非root用户)
## gives the user the appropriate permissions to the newly created
grant all privileges on *.* to 'username'@'%' identified by 'password' with grant option; # grant 修改用户权限的关键字 # all(增、删、改、查、创建数据库和表等,除grant外的所有权限) # on 后面跟数据库名.表名(*代表所有) # to 'username'@'ip'(%代表所有IP均可访问该数据库) # identified by 'password' # 关键字:privileges、with grant option
## must be flush privileges of the two cases
1, change the password.

2, ultra-authorized users.

The role essentially flush privileges command the current user is the user information and privilige table / permissions extracted from the mysql database (MySQL database built-in library) into memory

Guess you like

Origin www.cnblogs.com/mousecode/p/12497538.html