- net stop mysql 注:停止mysql服务
- net start mysql 注:启动mysql服务
- mysql -u用户名 -p用户密码 注:登陆本机的mysql
- mysql -u用户名 -p用户密码 -h机器IP 注:登陆指定主机的mysql
- grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"
- grant select,insert,update,delete on *.* to user1@localhost Identified by "password1";
- show databases;
- use mysql;
- show tables;
- describe 表名;
- create database 库名;
- drop database 库名;
- drop database if exists drop_database;
- use 库名;
- create table 表名(字段列表);
- drop table 表名;
- delete from 表名;
- select * from 表名;
- mysqldump --opt test > mysql.test
- mysqlimport -u root -p123456 < < mysql.dbname
- load data local infile "文件名" into table 表名;
- source d:/mysql.sql; 注:执行sql文本文件
- /. d:/mysql.sql 注:执行sql文本文件
- delimiter ; 注:设置执行分割符
- mysql> select * fro \c 注:\c取消当前执行
- mysql> select * from tablename\G; 注:\G垂直显示表格内容
- mysql> select * from tablename\g 注:\g表示执行(go),可以代替执行分隔符;
- mysql> select * from tablename limit 3; 注:限制返回结果最大3条
- exit; 注:退出
mysql自解析的命令:
- ? (\?) Synonym for `help'.
- clear (\c) Clear command.
- connect (\r) Reconnect to the server. Optional arguments are db and host.
- delimiter (\d) Set statement delimiter.
- edit (\e) Edit command with $EDITOR.
- ego (\G) Send command to mysql server, display result vertically.
- exit (\q) Exit mysql. Same as quit.
- go (\g) Send command to mysql server.
- help (\h) Display this help.
- nopager (\n) Disable pager, print to stdout.
- notee (\t) Don't write into outfile.
- pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
- print (\p) Print current command.
- prompt (\R) Change your mysql prompt.
- quit (\q) Quit mysql.
- rehash (\#) Rebuild completion hash.
- source (\.) Execute an SQL script file. Takes a file name as an argument.
- status (\s) Get status information from the server.
- system (\!) Execute a system shell command.
- tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
- use (\u) Use another database. Takes database name as argument.
- charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
- warnings (\W) Show warnings after every statement.
- nowarning (\w) Don't show warnings after every statement.