一、进入mysql
- 进入mysql容器(安装在docker里面),安装在物理机上的这一步省略。
docker ps
docker exec -it 容器id(容器名) bash
docker exec -it mysql-test bash
- 输入root账户进入mysql
mysql -u root -p密码
二、创建数据库
- 默认创建数据库的配置字符集
mysql> CREATE DATABASE testdb1;
查看数据:SHOW DATABASES;
删除数据库:DROP DATABASE testdb1;
- 也可以指定字符集
mysql> CREATE DATABASE testdb1 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Query OK, 0 rows affected (0.09 sec)
三、创建用户
create user 'test'@'%' identified by 'test';
Query OK, 0 rows affected (0.09 sec)
四、授权用户
mysql> grant all on *.* to 'test'@'%' ;
Query OK, 0 rows affected (0.10 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
五、查看数据库
1,选择mysql数据库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user,plugin from user;
两个root用户 ,'root'@'%','root'@'localhost'(只有本地参能连接)、搭建好mysql数据库后,记得修改两个root用户的密码,修改方式如下。
Navicat
1、创建数据库
mysql> CREATE DATABASE testdb1 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
2、创建用户
mysql> CREATE user 'test'@'%' identified by 'test123';
3、授权
grant all on testdb1 .* to 'test'@'%' ;
grant all on *.* to 'test'@'%' ;
4、刷新权限
flush privileges;
修改加密方式
- 修改密码为用不过期
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.02 sec)
- 修改密码并指定加密规则为mysql_native_password
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
- 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)