◆ 批处理模式:
你交互式地使用mysql输入查询并且查看结果,同时也可以以批模式运行mysql。把你想要运行的命令放在一个文件中,然后告诉mysql从文件读取它的输入:
shell> mysql < batch-file
shell> mysql -h host -u user -p < batch-file
Enter password: ********
◆ 登陆数据库:
shell> mysql -h host -u user -p
一些MySQL安装允许用户以“anoymous”(匿名)用户连接在本地主机上运行的服务器。如果在你的机器是这种情况,你应该能通过没有任何选项地调用mysql与该服务器连接:
shell> mysql
◆ 断开连接:
方式一:QUIT
方式二:Ctrl+D
◆ 取消命令:
如果你决定,你不想要执行你在输入过程中输入的一个命令,打入/c取消它:
/c
◆ 显示数据库:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| rat |
+--------------------+
2 rows in set (0.00 sec)
◆ 切换数据库:
mysql> USE test
Database changed
◆ 显示数据库中的表:
mysql> show tables;
+---------------+
| Tables_in_rat |
+---------------+
| account |
| customer |
+---------------+
2 rows in set (0.00 sec)
◆ 显示表信息:
mysql> describe account;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
| password | varchar(20) | NO | | NULL | |
| quota | int(10) | NO | | NULL | |
| money | int(10) | NO | | NULL | |
+----------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
◆ load数据:
mysql> load data infile 'C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\1.txt' into table fireworks fields terminated by ',';
出现如下异常时需先执行:
SET SQL_SAFE_UPDATES=0;
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.