Windows在控制檯訪問另一臺Windows下的mysql以及基本指令
Windows在控制檯訪問另一臺Windows下的mysql:
mysql -u root -h ip地址 -p
eg:
mysql -u root -h 123.123.123.123 -p
mysql基本指令:
1檢視mysql狀態信——status;
2顯示當前系統埠號——show variables like 'port';
3檢視資料庫系統所使用的引擎——show variables like '%storage_engine%';
4顯示mysql中支援的儲存引擎——show engines;
5幫助——help;
6檢視系統函式相關幫助——help functions;這時help等價於?
7檢視正在使用的資料庫——select database();
8檢視資料庫——show databases;
9查看錶——show tables;
10開啟我們的某一個數據庫——use mysql;
11建立自己的資料庫:
create database test01 ;
cteate database if not exists test01;
create database if not exists test01 character set 'utf8';
12檢視建立資料庫的語法——?create database;
Syntax:你看到的MySQL語法裡面的
大括號為:只寫一次
中括號為:可寫可不寫
13刪除資料庫:
drop database test01;
drop database if exists test01;
14建立表(語法參考——?create table):
create table test01(
id int(30) primary key auto_increment,如果int後面不寫,預設11位
name varchar(100) not null;
createdTime datatime not null
birth data not null
)[engine=OnnoDB] [default charset=utf-8];
15顯示錶結構——desc test01;
16顯示錶的建立語句——show create table test01;
17向表插入資料(inse):注意null必須寫
insert into test01(id,name,createdTime,birth) values (null,'A',now(),now());
insert into test01 values (null,'A',now(),now());
除非——insert into test01(name,createdTime,birth) values ('A',now(),now());
insert into test01 values (null,'A',now(),now()),(null,'B',now(),now();
18 select max(id) from test01;
19update test01 set name='AA' where id=1;
20delete from test01;刪除全部資料
delete from test01 where id=1;
21查詢分頁——select * from test01 limit 3;每頁最多顯示3條
select * from test01 limit 3,4;4為取得個數,最多取4條,3為從大於3開始取,取4條
select * from test01 order by id desc limit 6,3;
22執行sql檔案:
source d:/test01.sqlsource d:/test01.sql
*重要:set names utf8;然後source d:/test01.sqlsource d:/test01.sql
*重要:控制檯的編碼和資料庫的編碼不一樣解決:set names gbk;