MySQL使用备忘录

创建数据库,并指定该数据库的字符集编码为 utf8mb4

1
CREATE DATABASE `irenshi` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

用 root 权限创建名为 Vent 的数据库

1
mysqladmin -u root -p create Vent

把数据库’test’中的所有表的所有权限给用户’Frank’

1
2
3
mysql> grant all privileges on test.* to 'Frank'@'localhost'
-> ;
Query OK, 0 rows affected (0.01 sec)

登录’root’用户

1
mysql -u root -p

收回权限

“grant” -> “revoke”
“to” -> “from”

使用数据库’test’

use test;

创建用户

1
CREATE USER 'username'@'host' IDENTIFIED BY 'password';

删除用户

1
DROP USER 'username'@'host';

通过 brew 安装,启动mysql服务

1
brew install mysql
1
2
3
4
5
6
7
8
9
10
11
xiefengdeAir:~ Frank$ mysql.server stop
Shutting down MySQL
.. SUCCESS!
xiefengdeAir:~ Frank$ mysql.server start
Starting MySQL
. SUCCESS!
xiefengdeAir:~ Frank$ mysql.server restart
Shutting down MySQL
.... SUCCESS!
Starting MySQL
. SUCCESS!

修改默认值

1
alter table table_name alter column_name set default default_value;

修改指定表的字符集编码为 utf8mb4

1
ALTER TABLE [table_name] CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;