MySQL常用命令

登录数据库

1
mysql -h localhost -uroot -p

导出数据库

1
mysqldump -uroot -p db > db.sql

导入数据库

1
2
3
mysql -uroot -p db < db.sql
// or
mysql -uroot -p db -e "source /path/to/db.sql"

开启远程登录

1
2
3
4
5
grant all privileges on 'ss'.* to 'root'@'%' indentified by 'passoword' with grant option;
// or
update user set Host="%" and User="root"
// 注意%是不包含localhost的
flush privileges;

创建用户

1
CREATE USER 'test'@'localhost' IDENTIFIED BY 'password';

创建表

1
CREATE SCHEMA testdb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

刷新权限

1
flush privileges;

赋予数据库权限

1
GRANT ALL ON testdb.* TO 'test'@'localhost';