CREATETABLE mytable ( id INTPRIMARY KEY, name VARCHAR(50) );
插入数据:
INSERTINTO mytable (id, name) VALUES (1, 'John');
查询数据:
SELECT*FROM mytable;
更新数据:
UPDATE mytable SET name ='Alice'WHERE id =1;
删除数据:
DELETEFROM mytable WHERE id =1;
客户端常用命令
连接到mysql
mysql -u root -p
输入\h查看帮助:
List of all client commands: Note that all text commands must be first on line and end with ';' ? (\?) Synonym for `help'. clear (\c) Clear the current input statement. 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 MariaDB server, display result vertically. exit (\q) Exit mysql. Same as quit. go (\g) Send command to MariaDB 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. costs (\Q) Toggle showing query costs after each query 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.
For server side help, type 'help contents'
简单使用
连接:
mysql -u root -p
数据库操作:
CREATE DATABASE </database_name>; # 创建 DROP DATABASE </database_name>; # 删除 USE </database_name>; # 选择
数据表操作:
CREATE TABLE </table_name> (column_name column_type); # 创建表 CREATE TABLE IF NOT EXISTS </table_name> (column_name column_type); # 不存在则创建表 DROP TABLE </table_name>; # 删除表 INSERT INTO </table_name> ( field1, field2,...fieldN ) VALUES ( value1, value2,...valueN ); # 表中插入数据 SELECT * FROM </table_name>; # 从表中读取数据