- 登录:mysql -u root -p 回车,输入密码
- 添加新用户:grant usage on mydb.* to 'test1'@'local' identified by '123456' with grant option; (注:mydb为数据库名,test1为用户名,123456为密码)
- 为特定用户授权:grant select,insert,update,delete,create,drop on mydb.* to 'test1'@'localhost'; 或全权限:grant all privileges on mydb.* to 'test1'@'localhost'; flush privileges;
- show databases; show tables; desc user;
- 查看port号:show global variables like 'port';
- 启动mysql:service mysql start 或 /etc/inint.d/mysqld start
- 停止mysql:service mysql stop或 /etc/inint.d/mysqld stop
- 重启mysql:service mysql restart或 /etc/inint.d/mysqld restart
- 模糊查询:
- like 'abc%' :搜索以abc 开头的字符串的项
- like '%abc' :搜索以 abc结尾的字符串的项
- like '%abc%' :搜索包含abc 的字符串的项
- like '_abc' :搜索以abc结尾的项
- like '[a-z]abc' :搜索以abc结尾、以从 a到 z 的任何单个字母开头的项
- like 'A[^b]%' :搜索以字母A开头,并且第二个字母不是 b的项
- 查看和修改数据库系统的字符集:
show variables like 'character_set_%';set character_set_database='utf8';
- 创建数据库时设定字符编码&&修改已创建的数据库编码:
create database mydb character set utf8 collate utf8_general_ci;alter database mydb character set utf8 collate utf8_general_ci;
-
修改表和字段的编码:
alter table books_publisher character set utf8 collate utf8_general_ci;alter table books_publisher modify name varchar(30) character set utf8 collate utf8_general_ci;
-
查看某个字段编码&&所有编码&&数据库编码&&某张表编码:
select charset(name) from books_publisher;show character set;show create database mydb;show create table books_publisher;