mysql8.0 create users, database import and export

1. Create a user

create user 'jack'@'%' identified with mysql_native_password by 'jack123';

Jack means user name,% means no restriction on ip access (for example, if you change to localhost, you can only access it locally; or 127.0.0.1, you can only access it by user jack 127.0.0.1), jack123 means password, with mysql_native_password modify encryption by this command Rules, MySql8.0 version and 5.0 encryption rules are different, and the current visualization tools only support the old encryption method.
If you do not modify the encryption rules, when navicat is used to connect to the database, the following error will be prompted.
Insert picture description here
Looking at the user table under the mysql library, you can see that the default plugin for creating users is cache_sha2_password.
Insert picture description here
Only when it is mysql_native_password, can you use navicat to connect normally.
Modify the encryption method

ALTER USER 'jack'@'%' IDENTIFIED with mysql_native_password BY 'jack123'; 

2. Give permissions

grant all privileges on database_name.* to 'jack'@'%' with grant option;

database_name represents the database named database_name under the jack user, and * represents all tables under database_name. Examples:

grant select,insert on *.* to 'jack'@'%' with grant option;

Query and add permissions to all tables of all libraries under user jack.
Refresh permissions

flush privileges;

3. Set password never expires

ALTER USER 'jack'@'%' IDENTIFIED BY 'jack123' PASSWORD EXPIRE NEVER;
flush privileges;

Insert picture description here

4. Export

/usr/local/mysql/bin/mysqldump -ujack -p -R dbtest > /data/mysql_datas.sql
mysqldump -u 用户名 -p 数据库名 > 导出的文件名 

/ usr / local / mysql / bin is the mysql installation directory. After executing this command, enter the password.
-R (–routines) means to export stored procedures and custom functions.

5. Import

mysql -ujack -p  dbtest < /data/mysql_datas.sql
mysql -u用户名 -p 数据库名 < 导入的文件名

6. Log in to the database

Insert picture description here

Published 19 original articles · Likes2 · Visits 721

Guess you like

Origin blog.csdn.net/qq_40977118/article/details/104380177