一、 啟動(dòng)mysql服務(wù)
win+r輸入services.msc然后回車 ,打開服務(wù)管理策略文件。

image.png
找到你的MySQL然后右擊啟動(dòng),此時(shí)就能正常運(yùn)行。

image.png
二、 進(jìn)入退出mysql
登錄MYSQL
語法如下: mysql -u用戶名 -p用戶密碼
例如:
用戶名:root,密碼:root.
鍵入命令mysql -u root -p, 回車后提示你輸入密碼,輸入root,然后回車即可進(jìn)入到mysql中了,mysql的提示符是:mysql>
登錄成功后可以看到版本信息:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 72
Server version: 5.5.40 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
注意,如果是連接到另外的機(jī)器上,則需要加入一個(gè)參數(shù)-h機(jī)器IP
退出MYSQL
exit (回車)
三、 操作數(shù)據(jù)庫(kù)
登錄到mysql中,然后在mysql的提示符下運(yùn)行下列命令,每個(gè)命令以分號(hào)結(jié)束。
顯示數(shù)據(jù)庫(kù)列表:
show databases;
缺省有兩個(gè)數(shù)據(jù)庫(kù):mysql和test。 mysql庫(kù)存放著mysql的系統(tǒng)和用戶權(quán)限信息,我們改密碼和新增用戶,實(shí)際上就是對(duì)這個(gè)庫(kù)進(jìn)行操作。
執(zhí)行后,dos命令行如下所示:
+--------------------+
| Database |
+--------------------+
| information_schema |
| db_android |
| mysql |
| performance_schema |
| test |
+--------------------+
指定當(dāng)前工作數(shù)據(jù)庫(kù)
use 數(shù)據(jù)庫(kù)名稱;
use db_android;
指定數(shù)據(jù)后dos命令變化如下
mysql> use db_android;
Database changed
mysql>
修改數(shù)據(jù)庫(kù)
alter database 數(shù)據(jù)庫(kù)名稱;
mysql> alter database db_android default character set gb2312;
Query OK, 1 row affected (0.00 sec)
創(chuàng)建數(shù)據(jù)庫(kù):
create database 庫(kù)名;
create database db_zxn if not exists;
創(chuàng)建成功:
mysql> create database db_zxn;
Query OK, 1 row affected (0.00 sec)
刪除數(shù)據(jù)庫(kù)
drop database 庫(kù)名;
drop database db_zxn if exists;
刪除成功:
mysql> drop database db_zxn;
Query OK, 0 rows affected (0.02 sec)