1 开始使用mysql
bin> mysql -u $username -p
2 show all databases
mysql> show databases;
3 use a database
mysql> use $databaseName;
4 show all tables
mysql> show tables;
5 show database character
mysql> show variables like '%char%';
6 change database character
mysql> set character_set_database=$characterName;
7 import database
mysql> source $sqlFileName;
8 export database
mysql> mysqldump -p $databaseName > $sqlFileName;
9 export table
mysql> mysqldump -p $databaseName $tableName > $sqlFileName;
10 export table by query condition
mysql> mysqldump -p -where=$queryCondition $databaseName $tableName > $sqlFileName;
11 remote vistor mysql
mysql -h $ip -P $port -u $name -p
12 view mysql parameter
mysql -V
mysql> status;
13 quit mysql
mysql>quit;
14 mysql 远程访问权限 *代表所有 %任何ip
MYSQL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
MYSQL> FLUSH PRIVILEGES;
# 第二种
MYSQL> GRANT ALL PRIVILEGES ON $database.$table.* TO '$user'@'$ip' IDENTIFIED BY '$password' WITH GRANT OPTION;
MYSQL> FLUSH PRIVILEGES;
#第三种
MYSQL> update user set host = '%' where user = 'root';
#mysql数据库user表会增加一条用户记录
15 删除带有外键约束的表的记录
1 先解除所有外键约束
ALTER TABLE 表名 NOCHECK CONSTRAINT 外键约束名;
2 然后执行自己的单条或多条删除
DELETE FROM 表名 WHERE 1=1;
3 删除后恢复外键约束
ALTER TABLE 表名 CHECK CONSTRAINT 外键约束名;