MYSQL基本操作

mysql常用命令

  • 登陆: mysql -h host -u username -p
  • 列出数据库:SHOW DATABESES;
  • 列出表:SHOW TABLES;
  • 列出表结构:DESC table_name
  • 使用一个数据库:USE database_name;
  • 导入:source 'file';
  • 导出:mysqldump -h 127.0.0.1 -u root -p "database_name" "table_name" --where="condition" > file_name.sql;
  • 查看慢日志:mysqldumpslow -s [c:按记录次数排序/t:时间/l:锁定时间/r:返回的记录数] -t [n:前n条数据] -g "正则" /path
  • 新增用户: insert into user(HostUserauthentication_string) value('localhost', 'username', password('pwd'))

mysql 5.7 新增用户

// 插入新用户
insert into mysql.user(Host, User, authentication_string, ssl_cipher, x509_issuer, x509_subject
value('localhost', 'username', password('password'), '', '', '');

// 数据库授权
grant all privileges on dbname.name.* to username@localhost identified by 'password';

// 刷新权限信息
FLUSH PRIVILEGES;
posted @ 2017-11-03 17:55  Sanplit  阅读(163)  评论(0)    收藏  举报