qjfy
1
docker exec -it mysql /bin/bash
mysql -uroot -p密码
CREATE USER '用户名'@'主机名' IDENTIFIED BY '密码';
主机名:哪个主机上可以登陆,使用通配符'%' 所有情况都能访问, 'localhost' 本地用户访问, '1.2.3.6' 指定 ip 才能访问
flush privileges;
CREATE DATABASE [IF NOT EXISTS] <数据库名>
[[DEFAULT] CHARACTER SET <字符集名>]
[[DEFAULT] COLLATE <校对规则名>];
CREATE DATABASE IF NOT EXISTS `wordpress` default character set utf8mb4 collate utf8mb4_unicode_ci;
- 授予权限用户wordpress操作wordpress数据库权限
GRANT privileges ON databasename.tablename TO 'username'@'host'
databasename:数据库名
tablename:表名,授予该用户对所有数据库和表的相应操作权限则可用*表示,如*.*
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%';
flush privileges;
qjfy
2
例子
mysql -uroot -p123456
- 创建chevereto数据库,字符集utf8mb4
CREATE DATABASE IF NOT EXISTS chevereto CHARACTER SET utf8mb4 collate utf8mb4_unicode_ci;
show databases;
select user from mysql.user;
CREATE USER 'chevereto'@'%' IDENTIFIED BY '123456';
- 授权chevereto用户chevereto数据库权限
GRANT ALL PRIVILEGES ON *.* TO 'chevereto'@'%' IDENTIFIED BY '123456';
flush privileges;
show grants for test;