基于Windows下的MySQL學(xué)習(xí)記錄
01.進(jìn)入MySQL
安裝好MySQL后缸托,打開cmd命令提示符窗口,輸入以下命令即可進(jìn)入MySQL瘾蛋,接著可以進(jìn)行后續(xù)操作俐镐。
mysql -hlocalhost -uroot -p
#以下是輸入輸出結(jié)果:
C:\Users\shanlin>mysql -hlocalhost -uroot -p
Enter password: *
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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.
02.基本查看操作
#查看所有數(shù)據(jù)庫(注意所有語句以分號(hào)結(jié)束)
show databases;
#退出數(shù)據(jù)庫(也可以使用鍵盤Ctrl+C退出)
exit
#進(jìn)入某個(gè)數(shù)據(jù)庫
use databasename;
#如"use mysql;"表示進(jìn)入mysql這個(gè)數(shù)據(jù)庫進(jìn)行操作
#查看允許登錄的帳戶
use mysql;
select host,user from user;
#允許MySQL的root帳戶進(jìn)行遠(yuǎn)程登錄,可以將
update user set host ='%' where user='root'
#清除緩存哺哼,F(xiàn)LUSH語句告訴服務(wù)器重載授權(quán)表
flush privileges;
#授權(quán)某個(gè)ip地址訪問數(shù)據(jù)庫
#例如:讓newuser用戶使用newpwd密碼從IP:192.168.1.3主機(jī)鏈接到mysql服務(wù)器
GRANT ALL PRIVILEGES ON *.* TO ‘newuser’@’192.168.1.3′ IDENTIFIED
BY ‘newpwd’ WITH GRANT OPTION;
#grant語法:grant 權(quán)限名(所有的權(quán)限用all) on 庫名(*全部).表名(*全部)
#to ‘要授權(quán)的用戶名’@’%’(%表示所有的IP佩抹,可以只些一個(gè)IP) identified by “密碼”叼风;
#身份檢查使用user表(Host, User和Password)3個(gè)范圍列執(zhí)行。
#服務(wù)器只有在user表記錄的Host和User列匹配客戶端主機(jī)名和用戶名棍苹,
#并且提供了正確的密碼時(shí)才接受連接无宿。
參考鏈接:設(shè)置MySQL允許外部IP訪問
03.數(shù)據(jù)庫創(chuàng)建,查看
#創(chuàng)建數(shù)據(jù)庫名稱為ms的數(shù)據(jù)庫
create database ms;
#刪除數(shù)據(jù)庫
drop database ms;
#查看數(shù)據(jù)庫
show databases;
#進(jìn)入某個(gè)數(shù)據(jù)庫
use ms;
#創(chuàng)建表
CREATE TABLE project (
id INT(20) not null AUTO_INCREMENT,
project_name VARCHAR(255) not null,
project_typeid int(20),
create_date DATE,
primary key(id)
);
#刪除表
drop table project;
#插入數(shù)據(jù)(輸入中文字符報(bào)錯(cuò)枢里,設(shè)置了utf8字符集也不行孽鸡,怪怪的)
insert into project(
project_name,
project_typeid,
create_date
)
values (
"damowang1",
'1',
'2016-5-3'
);
#查看數(shù)據(jù)
select * from project;
mysql> select * from project;
+----+--------------+----------------+-------------+
| id | project_name | project_typeid | create_date |
+----+--------------+----------------+-------------+
| 1 | Damowang2 | 1 | 2016-05-03 |
| 2 | damowang1 | 1 | 2016-05-03 |
+----+--------------+----------------+-------------+
2 rows in set (0.00 sec)
今天就到這里。