以管理员身份进入
1 启动数据库(关闭stop)
C:\Windows\system32>net start mysql
请求的服务已经启动。
2 输入账号密码登录数据库
C:\Windows\system32>mysql -h 127.0.0.1 -u root -p
Enter password: ******
查看帮助
mysql> help
For information about MySQL products and services, visit:
http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
https://shop.mysql.com/
List of all MySQL 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.
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.
notee (\t) Don't write into outfile.
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.
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> status
--------------
mysql Ver 14.14 Distrib 5.5.40, for Win64 (x86)
Connection id: 1
Current database:
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.5.40 MySQL Community Server (GPL)
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 2 min 15 sec
Threads: 1 Questions: 5 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.037
--------------
3 显示数据库
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mybatis |
| mybatis_plus |
| mysql |
| performance_schema |
| province |
| rbac |
| redis01 |
| seckill |
| ssmbuild |
| test |
| xxl_job |
+--------------------+
12 rows in set (0.01 sec)
4 使用指定数据库
mysql> use test
Database changed
5 显示数据库中的表
mysql> show tables
-> ;
+----------------+
| Tables_in_test |
+----------------+
| t_student |
| user |
+----------------+
2 rows in set (0.00 sec)
6 查询mysql数据库编码
mysql> show variables like %char%
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%char%' at line 1
mysql> show variables like "%char%";
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | D:\tools\mysql\share\charsets\ |
+--------------------------+--------------------------------+
8 rows in set (0.00 sec)
7 进行DML操作
mysql> select * from user;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | 2 | 12 |
| 2 | 3 | 12 |
| 3 | 4 | 23 |
| 4 | 1 | 23 |
| 5 | 5 | 33 |
| 6 | 0 | 33 |
+----+------+------+
6 rows in set (0.01 sec)