MySQL鏁版嵁搴撳父鐢ㄥ懡浠�

MySQL 鏁版嵁搴撳父鐢ㄥ懡浠�

1銆丮ySQL甯哥敤鍛戒护

create database name; 鍒涘缓鏁版嵁搴�

use databasename; 閫夋嫨鏁版嵁搴�

drop database name 鐩存帴鍒犻櫎鏁版嵁搴擄紝涓嶆彁閱�

show tables; 鏄剧ず琛�

describe tablename; 琛ㄧ殑璇︾粏鎻忚堪

select 涓姞涓奷istinct鍘婚櫎閲嶅瀛楁

mysqladmin drop databasename 鍒犻櫎鏁版嵁搴撳墠锛屾湁鎻愮ず銆�

鏄剧ず褰撳墠mysql鐗堟湰鍜屽綋鍓嶆棩鏈�

select version(),current_date;

2銆佷慨鏀筸ysql涓璻oot鐨勫瘑鐮侊細

shell>mysql -u root -p

mysql> update user set password=password(鈥漻ueok654123鈥�) where user=鈥檙oot鈥�;

mysql> flush privileges //鍒锋柊鏁版嵁搴�

mysql>use dbname锛� 鎵撳紑鏁版嵁搴擄細

mysql>show databases; 鏄剧ず鎵�鏈夋暟鎹簱

mysql>show tables; 鏄剧ず鏁版嵁搴搈ysql涓墍鏈夌殑琛細鍏坲se mysql锛涚劧鍚�

mysql>describe user; 鏄剧ず琛╩ysql鏁版嵁搴撲腑user琛ㄧ殑鍒椾俊鎭級锛�

3銆乬rant

鍒涘缓涓�涓彲浠ヤ粠浠讳綍鍦版柟杩炴帴鏈嶅姟鍣ㄧ殑涓�涓畬鍏ㄧ殑瓒呯骇鐢ㄦ埛锛屼絾鏄繀椤讳娇鐢ㄤ竴涓彛浠omething鍋氳繖涓�

mysql> grant all privileges on *.* to user@localhost identified by 鈥檚omething鈥� with

澧炲姞鏂扮敤鎴�

鏍煎紡锛歡rant select on 鏁版嵁搴�.* to 鐢ㄦ埛鍚岪鐧诲綍涓绘満 identified by 鈥滃瘑鐮佲��

GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY 鈥檚omething鈥� WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO monty@鈥�%鈥� IDENTIFIED BY 鈥檚omething鈥� WITH GRANT OPTION;

鍒犻櫎鎺堟潈锛�

mysql> revoke all privileges on *.* from root@鈥�%鈥�;

mysql> delete from user where user=鈥漴oot鈥� and host=鈥�%鈥�;

mysql> flush privileges;

鍒涘缓涓�涓敤鎴穋ustom鍦ㄧ壒瀹氬鎴风it363.com鐧诲綍锛屽彲璁块棶鐗瑰畾鏁版嵁搴揻angchandb

mysql >grant select, insert, update, delete, create,drop on fangchandb.* to custom@ it363.com identified by 鈥� passwd鈥�

閲嶅懡鍚嶈〃:

mysql > alter table t1 rename t2;

4銆乵ysqldump

澶囦唤鏁版嵁搴�

shell> mysqldump -h host -u root -p dbname >dbname_backup.sql

鎭㈠鏁版嵁搴�

shell> mysqladmin -h myhost -u root -p create dbname

shell> mysqldump -h host -u root -p dbname < dbname_backup.sql

濡傛灉鍙兂鍗稿嚭寤鸿〃鎸囦护锛屽垯鍛戒护濡備笅锛�

shell> mysqladmin -u root -p -d databasename > a.sql

濡傛灉鍙兂鍗稿嚭鎻掑叆鏁版嵁鐨剆ql鍛戒护锛岃�屼笉闇�瑕佸缓琛ㄥ懡浠わ紝鍒欏懡浠ゅ涓嬶細

shell> mysqladmin -u root -p -t databasename > a.sql

閭d箞濡傛灉鎴戝彧鎯宠鏁版嵁锛岃�屼笉鎯宠浠�涔坰ql鍛戒护鏃讹紝搴旇濡備綍鎿嶄綔鍛紵

mysqldump -T./ phptest driver

鍏朵腑锛屽彧鏈夋寚瀹氫簡-T鍙傛暟鎵嶅彲浠ュ嵏鍑虹函鏂囨湰鏂囦欢锛岃〃绀哄嵏鍑烘暟鎹殑鐩綍锛�./琛ㄧず褰撳墠鐩綍锛屽嵆涓巑ysqldump鍚屼竴鐩綍銆傚鏋滀笉鎸囧畾driver 琛紝鍒欏皢鍗稿嚭鏁翠釜鏁版嵁搴撶殑鏁版嵁銆傛瘡涓〃浼氱敓鎴愪袱涓枃浠讹紝涓�涓负.sql鏂囦欢锛屽寘鍚缓琛ㄦ墽琛屻�傚彟涓�涓负.txt鏂囦欢锛屽彧鍖呭惈鏁版嵁锛屼笖娌℃湁sql鎸囦护銆�

5銆佸彲灏嗘煡璇㈠瓨鍌ㄥ湪涓�涓枃浠朵腑骞跺憡璇塵ysql浠庢枃浠朵腑璇诲彇鏌ヨ鑰屼笉鏄瓑寰呴敭鐩樿緭鍏ャ�傚彲鍒╃敤澶栧3绋嬪簭閿叆閲嶅畾鍚戝疄鐢ㄧ▼搴忔潵瀹屾垚杩欓」宸ヤ綔銆�

渚嬪锛屽鏋滃湪鏂囦欢my_file.sql 涓瓨鏀炬湁鏌�

璇紝鍙涓嬫墽琛岃繖浜涙煡璇細

渚嬪锛屽鏋滄偍鎯冲皢寤鸿〃璇彞鎻愬墠鍐欏湪sql.txt涓�:

mysql > mysql -h myhost -u root -p database < sql.txt

杞浇澹版槑锛�鏈枃杞嚜http://news.newhua.com/news1/program_database/2009/217/0921715343537K7H7IDI2CCI09JCI1DK8FJ4B07B3A04219G561C3JAB.html

================================================================================

杞� mysql鍛戒护

涓� . 瀹夎涓庨厤缃甅YSQL

浜� . 甯哥敤mysql鍛戒护琛屽懡浠�1 .mysql鐨勫惎鍔ㄤ笌鍋滄

鍚姩MYSQL鏈嶅姟 net start mysql

鍋滄MYSQL鏈嶅姟 net stop mysql

2 . netstat 鈥搉a | findstr 3306 鏌ョ湅琚洃鍚殑绔彛 , findstr鐢ㄤ簬鏌ユ壘鍚庨潰鐨勭鍙f槸鍚﹀瓨鍦�

3 . 鍦ㄥ懡浠よ涓櫥闄哅YSQL鎺у埗鍙� , 鍗充娇鐢� MYSQL COMMEND LINE TOOL

璇硶鏍煎紡 mysql 鈥搖ser=root 鈥損assword=123456 db_name

鎴� mysql 鈥搖 root 鈥損123456 db_name

4 . 杩涘叆MYSQL鍛戒护琛屽伐鍏峰悗 , 浣跨敤status; 鎴�/s 鏌ョ湅杩愯鐜淇℃伅

5 . 鍒囨崲杩炴帴鏁版嵁搴撶殑璇硶 : use new_dbname;

6 . 鏄剧ず鎵�鏈夋暟鎹簱 : show databases;

7 . 鏄剧ず鏁版嵁搴撲腑鐨勬墍鏈夎〃 : show tables;

8 . 鏄剧ず鏌愪釜琛ㄥ垱寤烘椂鐨勫叏閮ㄤ俊鎭� : show create table table_name;

9 . 鏌ョ湅琛ㄧ殑鍏蜂綋灞炴�т俊鎭強琛ㄤ腑鍚勫瓧娈电殑鎻忚堪

Describe table_name; 缂╁啓褰㈠紡 : desc table_name;

涓� 銆� MySql涓殑SQL璇彞

1 . 鏁版嵁搴撳垱寤� : Create database db_name;

鏁版嵁搴撳垹闄� : Drop database db_name; 鍒犻櫎鏃跺彲鍏堝垽鏂槸鍚﹀瓨鍦紝鍐欐垚 : drop database if exits db_name

2 . 寤鸿〃 : 鍒涘缓鏁版嵁琛ㄧ殑璇硶 : create table table_name (瀛楁1 鏁版嵁绫诲瀷 , 瀛楁2 鏁版嵁绫诲瀷);

渚� : create table mytable (id int , username char(20));

鍒犺〃 : drop table table_name; 渚� : drop table mytable;

8 . 娣诲姞鏁版嵁 : Insert into 琛ㄥ悕 [(瀛楁1 , 瀛楁2 , 鈥�.)] values (鍊�1 , 鍊�2 , 鈥�..);

濡傛灉鍚戣〃涓殑姣忎釜瀛楁閮芥彃鍏ヤ竴涓��,閭d箞鍓嶉潰 [ ] 鎷彿鍐呭瓧娈靛悕鍙啓涔熷彲涓嶅啓

渚� : insert into mytable (id,username) values (1,鈥檢hangsan鈥�);

9 . 鏌ヨ : 鏌ヨ鎵�鏈夋暟鎹� : select * from table_name;

鏌ヨ鎸囧畾瀛楁鐨勬暟鎹� : select 瀛楁1 , 瀛楁2 from table_name;

渚� : select id,username from mytable where id=1 order by desc;澶氳〃鏌ヨ璇彞------------鍙傜収绗�17鏉″疄渚�

10 . 鏇存柊鎸囧畾鏁版嵁 , 鏇存柊鏌愪竴涓瓧娈电殑鏁版嵁锛堟敞鎰忥紝涓嶆槸鏇存柊瀛楁鐨勫悕瀛楋級

Update table_name set 瀛楁鍚�=鈥欐柊鍊尖�� [, 瀛楁2 =鈥欐柊鍊尖�� , 鈥�..][where id=id_num] [order by 瀛楁 椤哄簭]

渚� : update mytable set username=鈥檒isi鈥� where id=1;

Order璇彞鏄煡璇㈢殑椤哄簭 , 濡� : order by id desc(鎴朼sc) , 椤哄簭鏈変袱绉� : desc鍊掑簭(100鈥�1,鍗充粠鏈�鏂版暟鎹線鍚庢煡璇�),asc(浠�1-100)锛學here鍜宱rder璇彞涔熷彲鐢ㄤ簬鏌ヨselect 涓庡垹闄elete

11 . 鍒犻櫎琛ㄤ腑鐨勪俊鎭� :

鍒犻櫎鏁翠釜琛ㄤ腑鐨勪俊鎭� : delete from table_name;

鍒犻櫎琛ㄤ腑鎸囧畾鏉′欢鐨勮鍙� : delete from table_name where 鏉′欢璇彞 ; 鏉′欢璇彞濡� : id=3;

12 . 鍒涘缓鏁版嵁搴撶敤鎴�

涓�娆″彲浠ュ垱寤哄涓暟鎹簱鐢ㄦ埛濡傦細

CREATE USER username1 identified BY 鈥榩assword鈥� , username2 IDENTIFIED BY 鈥榩assword鈥欌��.

13 . 鐢ㄦ埛鐨勬潈闄愭帶鍒讹細grant

搴擄紝琛ㄧ骇鐨勬潈闄愭帶鍒� : 灏嗘煇涓簱涓殑鏌愪釜琛ㄧ殑鎺у埗鏉冭祴浜堟煇涓敤鎴�

Grant all ON db_name.table_name TO user_name [ indentified by 鈥榩assword鈥� ];

14 . 琛ㄧ粨鏋勭殑淇敼

锛�1锛夊鍔犱竴涓瓧娈垫牸寮忥細

alter table table_name add column (瀛楁鍚� 瀛楁绫诲瀷); ----姝ゆ柟娉曞甫鎷彿

锛�2锛夋寚瀹氬瓧娈垫彃鍏ョ殑浣嶇疆锛�

alter table table_name add column 瀛楁鍚� 瀛楁绫诲瀷 after 鏌愬瓧娈碉紱

鍒犻櫎涓�涓瓧娈碉細

alter table table_name drop瀛楁鍚�;

锛�3锛変慨鏀瑰瓧娈靛悕绉�/绫诲瀷

alter table table_name change 鏃у瓧娈靛悕 鏂板瓧娈靛悕 鏂板瓧娈电殑绫诲瀷;

锛�4锛夋敼琛ㄧ殑鍚嶅瓧

alter table table_name rename to new_table_name;

锛�5锛変竴娆℃�ф竻绌鸿〃涓殑鎵�鏈夋暟鎹�

truncate table table_name; 姝ゆ柟娉曚篃浼氫娇琛ㄤ腑鐨勫彇鍙峰櫒(ID)浠�1寮�濮�

15 . 澧炲姞涓婚敭锛屽閿紝绾︽潫锛岀储寮曘�傘�傘�傘��(浣跨敤鏂规硶瑙�17瀹炰緥)

鈶� 绾︽潫锛堜富閿甈rimary key銆佸敮涓�鎬nique銆侀潪绌篘ot Null锛�

鈶� 鑷姩澧炲紶 auto_increment

鈶㈠閿瓼oreign key-----涓巖eference table_name(col_name鍒楀悕)閰嶅悎浣跨敤锛屽缓琛ㄦ椂鍗曠嫭浣跨敤

鈶� 鍒犻櫎澶氫釜琛ㄤ腑鏈夊叧鑱旂殑鏁版嵁----璁剧疆foreign key 涓簊et null ---鍏蜂綋璁剧疆鍙傝�冨府鍔╂枃妗�

16 . 鏌ョ湅鏁版嵁搴撳綋鍓嶅紩鎿�

SHOW CREATE TABLE table_name;

淇敼鏁版嵁搴撳紩鎿�

ALTER TABLE table_name ENGINE=MyISAM | InnoDB;

17 . SQL璇彞杩愮敤瀹炰緥:

--1 寤簎sers琛�

create table users (id int primary key auto_increment,nikename varchar(20) not null unique,password varchar(100) not null,address varchar(200), reg_date timestamp not null default CURRENT_TIMESTAMP);

--2 寤篴rticles琛�,鍦ㄥ缓琛ㄦ椂璁剧疆澶栭敭

create table articles (id int primary key auto_increment,content longtext not null,userid int,constraint foreign key (userid) references users(id) on delete set null);

-----------------------------------------------------------------------

--2.1 寤篴rticles琛�,寤鸿〃鏃朵笉璁剧疆澶栭敭

create table articles (id int primary key auto_increment,content longtext not null,userid int);

--2.2 缁檃rticles琛ㄨ缃閿�

alter table articles add constraint foreign key (userid) references users(id) on delete set null;

------------------------------------------------------------------------

--3. 鍚憉sers琛ㄤ腑鎻掑叆鏁版嵁,鍚屾椂鎻掑叆澶氭潯

insert into users (id,nikename,password,address) values (1,'lyh1','1234',null),(10,'lyh22','4321','婀栧寳姝︽眽'),(null,'lyh333','5678', '鍖椾含娴锋穩');

--4. 鍚慳rticle涓彃鍏ヤ笁鏉℃暟鎹�

insert into articles (id,content,userid) values (2,'hahahahahaha',11),(null,'xixixixixix',10),(13,'aiaiaiaiaiaiaiaiaiaiaiaia',1),(14,'hohoahaoaoooooooooo',10);

--5. 杩涜澶氳〃鏌ヨ锛岄�夋嫨users琛ㄤ腑ID=10鐨勭敤鎴峰彂甯冪殑鎵�鏈夌暀瑷�鍙婅鐢ㄦ埛鐨勬墍鏈変俊鎭�

select articles.id,articles.content,users.* from users,articles where users.id=10 and articles.userid=users.id order by articles.id desc;

--6. 鏌ョ湅鏁版嵁搴撳紩鎿庣被鍨�

show create table users;

--7. 淇敼鏁版嵁搴撳紩鎿庣被鍨�

alter table users engine=MyISAM;---鍥犱负users琛ㄤ腑ID琚缃垚澶栭敭锛屾墽琛屾鍙ヤ細鍑洪敊

--8. 鍚岃〃鏌ヨ,宸茬煡涓�涓潯浠剁殑鎯呭喌涓�.鏌ヨID鍙峰ぇ浜庣敤鎴穕yh1鐨処D鍙风殑鎵�鏈夌敤鎴�

select a.id,a.nikename,a.address from users a,users b where b.nikename='lyh1' and a.id>b.id;

------涔熷彲鍐欐垚

select id,nikename,address from users where id>(select id from users where nikename='lyh1');

9. 鏄剧ず骞撮緞姣旈瀵艰繕澶х殑鍛樺伐锛�

select a.name from users a,users b where a.managerid=b.id and a.age>b.age;

鏌ヨ缂栧彿涓�2鐨勫彂甯栦汉: 鍏堟煡articles琛�,寰楀埌鍙戝笘浜虹殑缂栧彿,鍐嶆牴鎹紪鍙锋煡users寰楀埌鐨勭敤鎴峰悕銆�

鎺ョ潃鐢ㄥ叧鑱旀煡璇�.

select * from articles,users寰楀埌绗涘崱鍎跨Н,鍐嶅姞order by articles.id浠ヤ究瑙傚療

浣跨敤select * from articles,users where articles.id=2 绛涢�夊嚭2鍙峰笘瀛愪笌姣忎釜鐢ㄦ埛鐨勭粍鍚堣褰�

鍐嶄娇鐢╯elect * from articles,users where articles.id=2 and articles.userid=users.id閫夊嚭users.id绛変簬2鍙峰笘鐨勫彂甯栦汉id鐨勮褰�.

鍙彇鐢ㄦ埛鍚�:select user where user.id=(select userid from articles where article.id =2)

鎵惧嚭骞撮緞姣斿皬鐜嬭繕澶х殑浜�:鍋囪灏忕帇鏄�28宀�,鍏堟兂鎵惧嚭骞撮緞澶т簬28鐨勪汉

select * from users where age>(select age from users where name='xiaowang');

*****瑕佹煡璇㈢殑璁板綍闇�瑕佸弬鐓ц〃閲岄潰鐨勫叾浠栬褰�:

select a.name from users a,users b where b.name='xiaowang' and a.age>b.age

琛ㄩ噷鐨勬瘡涓敤鎴烽兘鎯硃k涓�涓�.select a.nickname,b.nickname from users a,users b where a.id>b.id ;

鏇翠繚闄╃殑璇彞:select a.nickname,b.nickname from (select * from users order by id) a,(se

lect * from users order by id) b where a.id>b.id ;

鍐嶆煡璇㈡煇涓汉鍙戠殑鎵�鏈夊笘瀛�.

select b.* from articles a , articles b where a.id=2 and a.userid=b.userid

璇存槑: 琛ㄤ箣闂村瓨鍦ㄧ潃鍏崇郴锛孍R姒傚康鐨勮В閲婏紝鐢╝ccess涓殑绀轰緥鏁版嵁搴撴紨绀鸿〃涔嬮棿鐨勫叧绯�.鍙湁innodb寮曟搸鎵嶆敮鎸乫oreign key锛宮ysql鐨勪换浣曞紩鎿庣洰鍓嶉兘涓嶆敮鎸乧heck绾︽潫銆�

鍥涖�佸瓧绗﹂泦鍑虹幇閿欒瑙e喅鍔炴硶

鍑虹幇鐨勯棶棰橈細

mysql> update users

-> set username='鍏崇窘'

-> where userid=2;

ERROR 1366 (HY000): Incorrect string value: '/xB9/xD8/xD3/xF0' for column 'usern

ame' at row 1

鍚戣〃涓彃鍏ヤ腑鏂囧瓧绗︽椂锛屽嚭鐜伴敊璇��

mysql> select * from users;

+--------+----------+

| userid | username |

+--------+----------+

| 2 | ???? |

| 3 | ???? |

| 4 | ?铆?霉 |

+--------+----------+

3 rows in set (0.00 sec)

琛ㄤ腑鐨勪腑鏂囧瓧绗︿綅涔辩爜銆�

瑙e喅鍔炴硶锛�

浣跨敤鍛戒护锛�

mysql> status;

--------------

mysql Ver 14.12 Distrib 5.0.45, for Win32 (ia32)

Connection id: 8

Current database: test

Current user: root@localhost

SSL: Not in use

Using delimiter: ;

Server version: 5.0.45-community-nt MySQL Community Edition (GPL)

Protocol version: 10

Connection: localhost via TCP/IP

Server characterset: latin1

Db characterset: latin1

Client characterset: gbk

Conn. characterset: gbk

TCP port: 3306

Uptime: 7 hours 39 min 19 sec

Threads: 2 Questions: 174 Slow queries: 0 Opens: 57 Flush tables: 1 Open ta

bles: 1 Queries per second avg: 0.006

--------------

鏌ョ湅mysql鍙戠幇Server characterset锛孌b characterset鐨勫瓧绗﹂泦璁炬垚浜唋atin1锛屾墍浠ュ嚭鐜颁腑鏂囦贡鐮併��

mysql> show tables;

+----------------+

| Tables_in_test |

+----------------+

| users |

+----------------+

1 row in set (0.00 sec)

鏇存敼琛ㄧ殑瀛楃闆嗐��

mysql> alter table users character set GBK;

Query OK, 3 rows affected (0.08 sec)

Records: 3 Duplicates: 0 Warnings: 0

鏌ョ湅琛ㄧ殑缁撴瀯锛�

mysql> show create users;

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 'users

' at line 1

mysql> show create table users;

+-------+-----------------------------------------------------------------------

------------------------------------------------------------------------------+

| Table | Create Table

|

+-------+-----------------------------------------------------------------------

------------------------------------------------------------------------------+

| users | CREATE TABLE `users` (

`userid` int(11) default NULL,

`username` char(20) character set latin1 default NULL

) ENGINE=InnoDB DEFAULT CHARSET=gbk |

+-------+-----------------------------------------------------------------------

------------------------------------------------------------------------------+

1 row in set (0.00 sec)

mysql> desc users;

+----------+----------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+----------+----------+------+-----+---------+-------+

| userid | int(11) | YES | | NULL | |

| username | char(20) | YES | | NULL | |

+----------+----------+------+-----+---------+-------+

2 rows in set (0.02 sec)

杩欐椂鍚戣〃涓彃鍏ヤ腑鏂囩劧鍚庢湁閿欒銆�

mysql> insert into users values(88,'涓枃');

ERROR 1366 (HY000): Incorrect string value: '/xD6/xD0/xCE/xC4' for column 'usern

ame' at row 1

mysql> insert into users values(88,'涓枃');

ERROR 1366 (HY000): Incorrect string value: '/xD6/xD0/xCE/xC4' for column 'usern

ame' at row 1

杩樿鏇存敼users琛ㄧ殑username鐨勫瓧绗﹂泦銆�

mysql> alter table users modify username char(20) character set gbk;

ERROR 1366 (HY000): Incorrect string value: '/xC0/xEE/xCB/xC4' for column 'usern

ame' at row 1

mysql> alter table users modify username char(20) character set gbk;

ERROR 1366 (HY000): Incorrect string value: '/xC0/xEE/xCB/xC4' for column 'usern

ame' at row 1

鍥犱负琛ㄤ腑宸茬粡鏈夋暟鎹紝鎵�浠ユ洿鏀箄sername瀛楃闆嗙殑鎿嶄綔娌℃湁鎴�***

娓呯┖users琛ㄤ腑鐨勬暟鎹�

mysql> truncate table users;

Query OK, 3 rows affected (0.01 sec)

浠庢柊鏇存敼user琛ㄤ腑username鐨勫瓧绗﹂泦

mysql> alter table users modify username char(20) character set gbk;

Query OK, 0 rows affected (0.06 sec)

Records: 0 Duplicates: 0 Warnings: 0

杩欐椂鍐嶆彃鍏ヤ腑鏂囧瓧绗︼紝鎻掑叆鎴�***銆�

mysql> insert into users values(88,'涓枃');

Query OK, 1 row affected (0.01 sec)

mysql> select * from users;

+--------+----------+

| userid | username |

+--------+----------+

| 88 | 涓枃 |

+--------+----------+

1 row in set (0.00 sec)

mysql>

杞浇澹版槑锛�鏈枃杞嚜http://hi.baidu.com/zhjlabm/blog/item/b939fc3307a1d445ad4b5fbd.html

================================================================================

瀛︿範MySQL甯哥敤鎿嶄綔鍛戒护

1銆佸惎鍔∕ySQL鏈嶅姟鍣�

瀹為檯涓婁笂绡囧凡璁插埌濡備綍鍚姩MySQL銆備袱绉嶆柟娉曪細 涓�鏄敤winmysqladmin锛屽鏋滄満鍣ㄥ惎鍔ㄦ椂宸茶嚜鍔ㄨ繍琛岋紝鍒欏彲鐩存帴杩涘叆涓嬩竴姝ユ搷浣溿�� 浜屾槸鍦―OS鏂瑰紡涓嬭繍琛� d:mysqlbinmysqld

2銆佽繘鍏ysql浜や簰鎿嶄綔鐣岄潰

鍦―OS鏂瑰紡涓嬶紝杩愯锛� d:mysqlbinmysql

鍑虹幇: mysql 鐨勬彁绀虹锛屾鏃跺凡杩涘叆mysql鐨勪氦浜掓搷浣滄柟寮忋��

濡傛灉鍑虹幇 "ERROR 2003: Can鈥瞭 connect to MySQL server on 鈥瞝ocalhost鈥� (10061)鈥滐紝

璇存槑浣犵殑MySQL杩樻病鏈夊惎鍔ㄣ��

3銆侀��鍑篗ySQL鎿嶄綔鐣岄潰

鍦╩ysql>鎻愮ず绗︿笅杈撳叆quit鍙互闅忔椂閫�鍑轰氦浜掓搷浣滅晫闈細

mysql> quit

Bye

浣犱篃鍙互鐢╟ontrol-D閫�鍑恒��

4銆佺涓�鏉″懡浠�

mysql> select version(),current_date();

+----------------+-----------------+

| version() | current_date() |

+----------------+-----------------+

| 3.23.25a-debug | 2001-05-17 |

+----------------+-----------------+

1 row in set (0.01 sec)

mysql>

姝ゅ懡浠よ姹俶ysql鏈嶅姟鍣ㄥ憡璇変綘瀹冪殑鐗堟湰鍙峰拰褰撳墠鏃ユ湡銆傚皾璇曠敤涓嶅悓澶у皬鍐欐搷浣滀笂杩板懡浠わ紝鐪嬬粨鏋滃浣曘�傜粨鏋滆鏄巑ysql鍛戒护鐨勫ぇ灏忓啓缁撴灉鏄竴鑷寸殑銆�

缁冧範濡備笅鎿嶄綔锛�

mysql>Select (20+5)*4;

mysql>Select (20+5)*4,sin(pi()/3);

mysql>Select (20+5)*4 AS Result,sin(pi()/3); (AS: 鎸囧畾鍋囧悕涓篟esult)

5銆佸琛岃鍙�

涓�鏉″懡浠ゅ彲浠ュ垎鎴愬琛岃緭鍏ワ紝鐩村埌鍑虹幇鍒嗗彿鈥滐紱鈥濅负姝細

bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center">

 mysql> select

-> USER()

-> ,

-> now()

->;

+--------------------+---------------------+

| USER() | now() |

+--------------------+---------------------+

| ODBC@localhost | 2001-05-17 22:59:15 |

+--------------------+---------------------+

1 row in set (0.06 sec)

mysql>

娉ㄦ剰涓棿鐨勯�楀彿鍜屾渶鍚庣殑鍒嗗彿鐨勪娇鐢ㄦ柟娉曘��

6銆佷竴琛屽鍛戒护

杈撳叆濡備笅鍛戒护锛�

mysql> SELECT USER(); SELECT NOW();

+------------------+

| USER() |

+------------------+

| ODBC@localhost |

+------------------+

1 row in set (0.00 sec)

+---------------------+

| NOW() |

+---------------------+

| 2001-05-17 23:06:15 |

+---------------------+

1 row in set (0.00 sec)

mysql>

娉ㄦ剰涓棿鐨勫垎鍙凤紝鍛戒护涔嬮棿鐢ㄥ垎鍙烽殧寮�銆�

7銆佹樉绀哄綋鍓嶅瓨鍦ㄧ殑鏁版嵁搴�

mysql> show databases;

+----------+

| Database |

+----------+

| mysql |

| test |

+----------+

2 row in set (0.06 sec)

mysql>

8銆侀�夋嫨鏁版嵁搴撳苟鏄剧ず褰撳墠閫夋嫨鐨勬暟鎹簱

mysql> USE mysql

Database changed

mysql>

(USE 鍜� QUIT 鍛戒护涓嶉渶瑕佸垎鍙风粨鏉熴�傦級

mysql> select database();

+---------------+

| database() |

+---------------+

| mysql |

+---------------+

1 row in set (0.00 sec)

9銆佹樉绀哄綋鍓嶆暟鎹簱涓瓨鍦ㄧ殑琛�

mysql> SHOW TABLES;

10銆佹樉绀鸿〃(db)鐨勫唴瀹�

mysql>select * from db;

11銆佸懡浠ょ殑鍙栨秷

褰撳懡浠よ緭鍏ラ敊璇�屽張鏃犳硶鏀瑰彉锛堝琛岃鍙ユ儏褰級鏃讹紝鍙鍦ㄥ垎鍙峰嚭鐜板墠灏卞彲浠ョ敤 c鏉ュ彇娑堣鏉″懡浠�

mysql> select

-> user()

-> c

mysql>

杩欐槸涓�浜涙渶甯哥敤鐨勬渶鍩烘湰鐨勬搷浣滃懡浠わ紝閫氳繃澶氭缁冧範灏卞彲浠ョ墷鐗㈡帉鎹備簡

==========================================================================

mysql鍛戒护

娴嬭瘯鐜锛歮ysql 5.0.45

銆愭敞锛氬彲浠ュ湪mysql涓�氳繃mysql> SELECT VERSION();鏉ユ煡鐪嬫暟鎹簱鐗堟湰銆�

鏁寸悊锛歭eo

涓�銆佽繛鎺YSQL銆�

鏍煎紡锛歮ysql -h涓绘満鍦板潃 -u鐢ㄦ埛鍚� 锛峱鐢ㄦ埛瀵嗙爜

1銆佽繛鎺ュ埌鏈満涓婄殑MYSQL銆�

棣栧厛鎵撳紑DOS绐楀彛锛岀劧鍚庤繘鍏ョ洰褰昺ysql/bin锛屽啀閿叆鍛戒护mysql -u root -p锛屽洖杞﹀悗鎻愮ず浣犺緭瀵嗙爜.娉ㄦ剰鐢ㄦ埛鍚嶅墠鍙互鏈夌┖鏍间篃鍙互娌℃湁绌烘牸锛屼絾鏄瘑鐮佸墠蹇呴』娌℃湁绌烘牸锛屽惁鍒欒浣犻噸鏂拌緭鍏ュ瘑鐮�.

濡傛灉鍒氬畨瑁呭ソMYSQL锛岃秴绾х敤鎴穜oot鏄病鏈夊瘑鐮佺殑锛屾晠鐩存帴鍥炶溅鍗冲彲杩涘叆鍒癕YSQL涓簡锛孧YSQL鐨勬彁绀虹鏄細 mysql>

2銆佽繛鎺ュ埌杩滅▼涓绘満涓婄殑MYSQL銆傚亣璁捐繙绋嬩富鏈虹殑IP涓猴細110.110.110.110锛岀敤鎴峰悕涓簉oot,瀵嗙爜涓篴bcd123銆傚垯閿叆浠ヤ笅鍛戒护锛�

mysql -h110.110.110.110 -u root -p 123;锛堟敞:u涓巖oot涔嬮棿鍙互涓嶇敤鍔犵┖鏍硷紝鍏跺畠涔熶竴鏍凤級

3銆侀��鍑篗YSQL鍛戒护锛� exit 锛堝洖杞︼級

浜屻�佷慨鏀瑰瘑鐮併��

鏍煎紡锛歮ysqladmin -u鐢ㄦ埛鍚� -p鏃у瘑鐮� password 鏂板瘑鐮�

1銆佺粰root鍔犱釜瀵嗙爜ab12銆傞鍏堝湪DOS涓嬭繘鍏ョ洰褰昺ysql/bin锛岀劧鍚庨敭鍏ヤ互涓嬪懡浠�

mysqladmin -u root -password ab12

娉細鍥犱负寮�濮嬫椂root娌℃湁瀵嗙爜锛屾墍浠�-p鏃у瘑鐮佷竴椤瑰氨鍙互鐪佺暐浜嗐��

2銆佸啀灏唕oot鐨勫瘑鐮佹敼涓篸jg345銆�

mysqladmin -u root -p ab12 password djg345

涓夈�佸鍔犳柊鐢ㄦ埛銆�

锛堟敞鎰忥細鍜屼笂闈笉鍚岋紝涓嬮潰鐨勫洜涓烘槸MYSQL鐜涓殑鍛戒护锛屾墍浠ュ悗闈㈤兘甯︿竴涓垎鍙蜂綔涓哄懡浠ょ粨鏉熺锛�

鏍煎紡锛歡rant select on 鏁版嵁搴�.* to 鐢ㄦ埛鍚岪鐧诲綍涓绘満 identified by 鈥滃瘑鐮佲��

1銆佸鍔犱竴涓敤鎴穞est1瀵嗙爜涓篴bc锛岃浠栧彲浠ュ湪浠讳綍涓绘満涓婄櫥褰曪紝骞跺鎵�鏈夋暟鎹簱鏈夋煡璇€�佹彃鍏ャ�佷慨鏀广�佸垹闄ょ殑鏉冮檺銆傞鍏堢敤root鐢ㄦ埛杩炲叆MYSQL锛岀劧鍚庨敭鍏ヤ互涓嬪懡浠わ細

grant select,insert,update,delete on *.* to [email=test1@鈥�%]test1@鈥�%[/email]鈥� Identified by 鈥渁bc鈥�;

浣嗗鍔犵殑鐢ㄦ埛鏄崄鍒嗗嵄闄╃殑锛屼綘鎯冲鏌愪釜浜虹煡閬搕est1鐨勫瘑鐮侊紝閭d箞浠栧氨鍙互鍦╥nternet涓婄殑浠讳綍涓�鍙扮數鑴戜笂鐧诲綍浣犵殑mysql鏁版嵁搴撳苟瀵逛綘鐨勬暟鎹彲浠ヤ负鎵�娆蹭负浜嗭紝瑙e喅鍔炴硶瑙�2銆�

2銆佸鍔犱竴涓敤鎴穞est2瀵嗙爜涓篴bc,璁╀粬鍙彲浠ュ湪localhost涓婄櫥褰曪紝骞跺彲浠ュ鏁版嵁搴搈ydb杩涜鏌ヨ銆佹彃鍏ャ�佷慨鏀广�佸垹闄ょ殑鎿嶄綔锛坙ocalhost鎸囨湰鍦颁富鏈猴紝鍗矼YSQL鏁版嵁搴撴墍鍦ㄧ殑閭e彴涓绘満锛夛紝

杩欐牱鐢ㄦ埛鍗充娇鐢ㄧ煡閬搕est2鐨勫瘑鐮侊紝浠栦篃鏃犳硶浠巌nternet涓婄洿鎺ヨ闂暟鎹簱锛屽彧鑳介�氳繃MYSQL涓绘満涓婄殑web椤垫潵璁块棶浜嗐��

grant select,insert,update,delete on mydb.* to [email=test2@localhost]test2@localhost[/email] identified by 鈥渁bc鈥�;

濡傛灉浣犱笉鎯硉est2鏈夊瘑鐮侊紝鍙互鍐嶆墦涓�涓懡浠ゅ皢瀵嗙爜娑堟帀銆�

grant select,insert,update,delete on mydb.* to [email=test2@localhost]test2@localhost[/email] identified by 鈥溾��;

涓嬬瘒鎴戞槸MYSQL涓湁鍏虫暟鎹簱鏂归潰鐨勬搷浣溿�傛敞鎰忥細浣犲繀椤婚鍏堢櫥褰曞埌MYSQL涓紝浠ヤ笅鎿嶄綔閮芥槸鍦∕YSQL鐨勬彁绀虹涓嬭繘琛岀殑锛岃�屼笖姣忎釜鍛戒护浠ュ垎鍙风粨鏉熴��

涓�銆佹搷浣滄妧宸�

1銆佸鏋滀綘鎵撳懡浠ゆ椂锛屽洖杞﹀悗鍙戠幇蹇樿鍔犲垎鍙凤紝浣犳棤椤婚噸鎵撲竴閬嶅懡浠わ紝鍙鎵撲釜鍒嗗彿鍥炶溅灏卞彲浠ヤ簡銆�

涔熷氨鏄浣犲彲浠ユ妸涓�涓畬鏁寸殑鍛戒护鍒嗘垚鍑犺鏉ユ墦锛屽畬鍚庣敤鍒嗗彿浣滅粨鏉熸爣蹇楀氨OK銆�

2銆佷綘鍙互浣跨敤鍏夋爣涓婁笅閿皟鍑轰互鍓嶇殑鍛戒护銆�

浜屻�佹樉绀哄懡浠�

1銆佹樉绀哄綋鍓嶆暟鎹簱鏈嶅姟鍣ㄤ腑鐨勬暟鎹簱鍒楄〃锛�

mysql> SHOW DATABASES;

娉ㄦ剰锛歮ysql搴撻噷闈㈡湁MYSQL鐨勭郴缁熶俊鎭紝鎴戜滑鏀瑰瘑鐮佸拰鏂板鐢ㄦ埛锛屽疄闄呬笂灏辨槸鐢ㄨ繖涓簱杩涜鎿嶄綔銆�

2銆佹樉绀烘暟鎹簱涓殑鏁版嵁琛細

mysql> USE 搴撳悕锛�

mysql> SHOW TABLES;

3銆佹樉绀烘暟鎹〃鐨勭粨鏋勶細

mysql> DESCRIBE 琛ㄥ悕;

4銆佸缓绔嬫暟鎹簱锛�

mysql> CREATE DATABASE 搴撳悕;

5銆佸缓绔嬫暟鎹〃锛�

mysql> USE 搴撳悕;

mysql> CREATE TABLE 琛ㄥ悕 (瀛楁鍚� VARCHAR(20), 瀛楁鍚� CHAR(1));

6銆佸垹闄ゆ暟鎹簱锛�

mysql> DROP DATABASE 搴撳悕;

7銆佸垹闄ゆ暟鎹〃锛�

mysql> DROP TABLE 琛ㄥ悕锛�

8銆佸皢琛ㄤ腑璁板綍娓呯┖锛�

mysql> DELETE FROM 琛ㄥ悕;

9銆佹樉绀鸿〃涓殑璁板綍锛�

mysql> SELECT * FROM 琛ㄥ悕;

10銆佸線琛ㄤ腑鎻掑叆璁板綍锛�

mysql> INSERT INTO 琛ㄥ悕 VALUES (鈥漢yq鈥�,鈥滿鈥�);

11銆佹洿鏂拌〃涓暟鎹細

mysql-> UPDATE 琛ㄥ悕 SET 瀛楁鍚�1=鈥檃',瀛楁鍚�2=鈥檅鈥� WHERE 瀛楁鍚�3=鈥檆';

12銆佺敤鏂囨湰鏂瑰紡灏嗘暟鎹鍏ユ暟鎹〃涓細

mysql> LOAD DATA LOCAL INFILE 鈥淒:/mysql.txt鈥� INTO TABLE 琛ㄥ悕;

13銆佸鍏�.sql鏂囦欢鍛戒护锛�

mysql> USE 鏁版嵁搴撳悕;

mysql> SOURCE d:/mysql.sql;

14銆佸懡浠よ淇敼root瀵嗙爜锛�

mysql> UPDATE mysql.user SET password=PASSWORD(鈥欐柊瀵嗙爜鈥�) WHERE User=鈥檙oot鈥�;

mysql> FLUSH PRIVILEGES;

15銆佹樉绀簎se鐨勬暟鎹簱鍚嶏細

mysql> SELECT DATABASE();

16銆佹樉绀哄綋鍓嶇殑user锛�

mysql> SELECT USER();

涓夈�佷竴涓缓搴撳拰寤鸿〃浠ュ強鎻掑叆鏁版嵁鐨勫疄渚�

drop database if exists school;//濡傛灉瀛樺湪SCHOOL鍒欏垹闄�

create database school;//寤虹珛搴揝CHOOL

use school;//鎵撳紑搴揝CHOOL

create table teacher//寤虹珛琛═EACHER

(

id int(3) auto_increment not null primary key,

name char(10) not null,

address varchar(50) default 鈥樻繁鍦斥��,

year date

);//寤鸿〃缁撴潫

//浠ヤ笅涓烘彃鍏ュ瓧娈�

insert into teacher values(鈥�,鈥檃llen鈥�,'澶ц繛涓�涓��,'1976-10-10鈥�);

insert into teacher values(鈥�,鈥檍ack鈥�,'澶ц繛浜屼腑鈥�,'1975-12-23鈥�);

濡傛灉浣犲湪mysql鎻愮ず绗﹂敭鍏ヤ笂闈㈢殑鍛戒护涔熷彲浠ワ紝浣嗕笉鏂逛究璋冭瘯銆�

锛�1锛変綘鍙互灏嗕互涓婂懡浠ゅ師鏍峰啓鍏ヤ竴涓枃鏈枃浠朵腑锛屽亣璁句负school.sql锛岀劧鍚庡鍒跺埌c://涓嬶紝骞跺湪DOS鐘舵�佽繘鍏ョ洰褰昜url=file:////mysql//bin]//mysql//bin[/url]锛岀劧鍚庨敭鍏ヤ互涓嬪懡浠わ細

mysql -uroot -p瀵嗙爜 < c://school.sql

濡傛灉鎴愬姛锛岀┖鍑轰竴琛屾棤浠讳綍鏄剧ず锛涘鏈夐敊璇紝浼氭湁鎻愮ず銆傦紙浠ヤ笂鍛戒护宸茬粡璋冭瘯锛屼綘鍙灏�//鐨勬敞閲婂幓鎺夊嵆鍙娇鐢級銆�

锛�2锛夋垨鑰呰繘鍏ュ懡浠よ鍚庝娇鐢� mysql> source c://school.sql; 涔熷彲浠ュ皢school.sql鏂囦欢瀵煎叆鏁版嵁搴撲腑銆�

鍥涖�佸皢鏂囨湰鏁版嵁杞埌鏁版嵁搴撲腑

1銆佹枃鏈暟鎹簲绗﹀悎鐨勬牸寮忥細瀛楁鏁版嵁涔嬮棿鐢╰ab閿殧寮�锛宯ull鍊肩敤[url=file:////n]//n[/url]鏉ヤ唬鏇�.渚嬶細

3 rose 澶ц繛浜屼腑 1976-10-10

4 mike 澶ц繛涓�涓� 1975-12-23

鍋囪浣犳妸杩欎袱缁勬暟鎹瓨涓簊chool.txt鏂囦欢锛屾斁鍦╟鐩樻牴鐩綍涓嬨��

2銆佹暟鎹紶鍏ュ懡浠� load data local infile 鈥渃://school.txt鈥� into table 琛ㄥ悕;

娉ㄦ剰锛氫綘鏈�濂藉皢鏂囦欢澶嶅埗鍒癧url=file:////mysql//bin]//mysql//bin[/url]鐩綍涓嬶紝骞朵笖瑕佸厛鐢╱se鍛戒护鎵撹〃鎵�鍦ㄧ殑搴撱��

浜斻�佸浠芥暟鎹簱

1.瀵煎嚭鏁翠釜鏁版嵁搴�

瀵煎嚭鏂囦欢榛樿鏄瓨鍦╩ysql/bin鐩綍涓�

mysqldump -u 鐢ㄦ埛鍚� -p 鏁版嵁搴撳悕 > 瀵煎嚭鐨勬枃浠跺悕

mysqldump -u user_name -p123456 database_name > outfile_name.sql

2.瀵煎嚭涓�涓〃

mysqldump -u 鐢ㄦ埛鍚� -p 鏁版嵁搴撳悕 琛ㄥ悕> 瀵煎嚭鐨勬枃浠跺悕

mysqldump -u user_name -p database_name table_name > outfile_name.sql

3.瀵煎嚭涓�涓暟鎹簱缁撴瀯

mysqldump -u user_name -p -d 鈥揳dd-drop-table database_name > outfile_name.sql

-d 娌℃湁鏁版嵁 鈥揳dd-drop-table 鍦ㄦ瘡涓猚reate璇彞涔嬪墠澧炲姞涓�涓猟rop table

4.甯﹁瑷�鍙傛暟瀵煎嚭

mysqldump -uroot -p 鈥揹efault-character-set=latin1 鈥搒et-charset=gbk 鈥搒kip-opt database_name > outfile_name.sql

鍏�佸鍏ユ暟鎹簱

渚嬪锛氭暟鎹簱鍚嶄负 dbTest

棣栧厛锛岃繘鍏ysql

mysql -uroot -p123456

鐒跺悗锛屽垱寤烘暟鎹簱

createdbTest

exit

鏈�鍚庯紝瀵煎叆鏁版嵁搴�

mysql -uroot -p123456dbTest

鏁版嵁搴撳強琛ㄥ鍑哄鍏ョず渚嬶細

瀵煎嚭鏁版嵁搴�

mysqldump -u root -p123456 gameTop >gameTop_db.sql

瀵煎嚭鏁版嵁搴撶殑琛�

mysqldump -u-p123456rootgameTopgametop800 >gameTop_table.sql

瀵煎嚭鏁版嵁搴撶殑鐗瑰畾琛�

mysqldump -u root -p123456gameTop--tablegametop800>gameTop_table.sql

瀵煎嚭鏁版嵁搴擄紙鍙缁撴瀯锛屼笉瑕佹暟鎹級

mysqldump -u root -p123456--opt -dgameTop >gameTop_db.sql

鎴栬��

mysqldump -u root -p123456-dgameTop >gameTop_db.sql

瀵煎嚭鏁版嵁搴擄紙鍙鏁版嵁锛屼笉瑕佺粨鏋勶級

mysqldump -u root -p123456-tgameTop >gameTop_db.sql

娉細涓嶅姞 -d 鍜� -t 鍒欐棦瀵煎嚭缁撴瀯锛屼篃瀵煎嚭鏁版嵁

mysqldump瀵煎嚭鎶涘嚭寮傚父锛�

mysqldump: Got error: 1044: Access denied for user 'username'@'%' to database 'dbname' when using LOCK TABLES

瑙e喅鍔炴硶锛屾坊鍔犲弬鏁�--skip-lock-tables锛�

mysqldump--skip-lock-tables-h172.88.12.102 -username-pAnJnVs3C2tYXyTwV dbname> dbname_bk.sql

--------------------------

瀵煎叆鏁版嵁搴擄細

鐧诲綍MySQL: 聽 聽 聽mysql -uroot -p123456

鍒涘缓鏁版嵁搴擄細 聽 聽create databasegameTop;

瀵煎叆鏁版嵁搴擄細

mysql -uroot -p123456gameTop

瀵煎叆鏁版嵁搴撹〃锛�

mysql -uroot -p123456聽gameTopgametop800

瀵煎叆鏁版嵁搴撹〃锛�

mysql -uroot -p123456聽gameTop 聽

杞浇澹版槑锛�鏈枃杞嚜http://blog.csdn.net/networld2002/archive/2009/04/23/4103407.aspx

==================================================================================

1:浣跨敤SHOW璇彞鎵惧嚭鍦ㄦ湇鍔″櫒涓婂綋鍓嶅瓨鍦ㄤ粈涔堟暟鎹簱锛�

mysql> SHOW DATABASES;

2:鍒涘缓涓�涓暟鎹簱MYSQLDATA

mysql> CREATE DATABASE MYSQLDATA;

3:閫夋嫨浣犳墍鍒涘缓鐨勬暟鎹簱

mysql> USE MYSQLDATA; (鎸夊洖杞﹂敭鍑虹幇Database changed 鏃惰鏄庢搷浣滄垚鍔燂紒)

4:鏌ョ湅鐜板湪鐨勬暟鎹簱涓瓨鍦ㄤ粈涔堣〃

mysql> SHOW TABLES;

5:鍒涘缓涓�涓暟鎹簱琛�

mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));

6:鏄剧ず琛ㄧ殑缁撴瀯锛�

mysql> DESCRIBE MYTABLE;

7:寰�琛ㄤ腑鍔犲叆璁板綍

mysql> insert into MYTABLE values (鈥漢yq鈥�,鈥滿鈥�);

8:鐢ㄦ枃鏈柟寮忓皢鏁版嵁瑁呭叆鏁版嵁搴撹〃涓紙渚嬪D:/mysql.txt锛�

mysql> LOAD DATA LOCAL INFILE 鈥淒:/mysql.txt鈥� INTO TABLE MYTABLE;

9:瀵煎叆.sql鏂囦欢鍛戒护锛堜緥濡侱:/mysql.sql锛�

mysql>use database;

mysql>source d:/mysql.sql;

10:鍒犻櫎琛�

mysql>drop TABLE MYTABLE;

11:娓呯┖琛�

mysql>delete from MYTABLE;

12:鏇存柊琛ㄤ腑鏁版嵁

mysql>update MYTABLE set sex=鈥漟鈥� where name=鈥檋yq鈥�;

浠ヤ笅鏄棤鎰忎腑鍦ㄧ綉缁滅湅鍒扮殑浣跨敤MySql鐨勭鐞嗗績寰�,

鍦╳indows涓璏ySql浠ユ湇鍔″舰寮忓瓨鍦紝鍦ㄤ娇鐢ㄥ墠搴旂‘淇濇鏈嶅姟宸茬粡鍚姩锛屾湭鍚姩鍙敤net start mysql鍛戒护鍚姩銆傝�孡inux涓惎鍔ㄦ椂鍙敤鈥�/etc/rc.d/init.d/mysqld start鈥濆懡浠わ紝娉ㄦ剰鍚姩鑰呭簲鍏锋湁绠$悊鍛樻潈闄愩��

鍒氬畨瑁呭ソ鐨凪ySql鍖呭惈涓�涓惈绌哄瘑鐮佺殑root甯愭埛鍜屼竴涓尶鍚嶅笎鎴凤紝杩欐槸寰堝ぇ鐨勫畨鍏ㄩ殣鎮o紝瀵逛簬涓�浜涢噸瑕佺殑搴旂敤鎴戜滑搴斿皢瀹夊叏鎬у敖鍙兘鎻愰珮锛屽湪杩欓噷搴旀妸鍖垮悕甯愭埛鍒犻櫎銆� root甯愭埛璁剧疆瀵嗙爜锛屽彲鐢ㄥ涓嬪懡浠よ繘琛岋細

use mysql;

delete from User where User=鈥�";

update User set Password=PASSWORD(鈥檔ewpassword鈥�) where User=鈥檙oot鈥�;

濡傛灉瑕佸鐢ㄦ埛鎵�鐢ㄧ殑鐧诲綍缁堢杩涜闄愬埗锛屽彲浠ユ洿鏂癠ser琛ㄤ腑鐩稿簲鐢ㄦ埛鐨凥ost瀛楁锛屽湪杩涜浜嗕互涓婃洿鏀瑰悗搴旈噸鏂板惎鍔ㄦ暟鎹簱鏈嶅姟锛屾鏃剁櫥褰曟椂鍙敤濡備笅绫讳技鍛戒护锛�

mysql -uroot -p;

mysql -uroot -pnewpassword;

mysql mydb -uroot -p;

mysql mydb -uroot -pnewpassword;

涓婇潰鍛戒护鍙傛暟鏄父鐢ㄥ弬鏁扮殑涓�閮ㄥ垎锛岃缁嗘儏鍐靛彲鍙傝�冩枃妗c�傛澶勭殑mydb鏄鐧诲綍鐨勬暟鎹簱鐨勫悕绉般��

鍦� 杩涜寮�鍙戝拰瀹為檯搴旂敤涓紝鐢ㄦ埛涓嶅簲璇ュ彧鐢╮oot鐢ㄦ埛杩涜杩炴帴鏁版嵁搴擄紝铏界劧浣跨敤root鐢ㄦ埛杩涜娴嬭瘯鏃跺緢鏂逛究锛屼絾浼氱粰绯荤粺甯︽潵閲嶅ぇ瀹夊叏闅愭偅锛屼篃涓嶅埄浜庣鐞嗘妧 鏈殑鎻愰珮銆傛垜浠粰涓�涓簲鐢ㄤ腑浣跨敤鐨勭敤鎴疯祴浜堟渶鎭板綋鐨勬暟鎹簱鏉冮檺銆傚涓�涓彧杩涜鏁版嵁鎻掑叆鐨勭敤鎴蜂笉搴旇祴浜堝叾鍒犻櫎鏁版嵁鐨勬潈闄愩��

MySql鐨勭敤鎴风鐞嗘槸閫氳繃 User琛ㄦ潵瀹炵幇鐨勶紝娣诲姞鏂扮敤鎴峰父鐢ㄧ殑鏂规硶鏈変袱涓紝涓�鏄湪User琛ㄦ彃鍏ョ浉搴旂殑鏁版嵁琛岋紝鍚屾椂璁剧疆鐩稿簲鐨勬潈闄愶紱浜屾槸閫氳繃GRANT鍛戒护鍒涘缓鍏锋湁鏌愮鏉冮檺鐨勭敤 鎴枫�傚叾涓璆RANT鐨勫父鐢ㄧ敤娉曞涓嬶細

grant all on mydb.* to NewUserName@HostName identified by 鈥減assword鈥� ;

grant usage on *.* to NewUserName@HostName identified by 鈥減assword鈥�;

grant select,insert,update on mydb.* to NewUserName@HostName identified by 鈥減assword鈥�;

grant update,delete on mydb.TestTable to NewUserName@HostName identified by 鈥減assword鈥�;

鑻� 瑕佺粰姝ょ敤鎴疯祴浜堜粬鍦ㄧ浉搴斿璞′笂鐨勬潈闄愮殑绠$悊鑳藉姏锛屽彲鍦℅RANT鍚庨潰娣诲姞WITH GRANT OPTION閫夐」銆傝�屽浜庣敤鎻掑叆User琛ㄦ坊鍔犵殑鐢ㄦ埛锛孭assword瀛楁搴旂敤PASSWORD 鍑芥暟杩涜鏇存柊鍔犲瘑锛屼互闃蹭笉杞ㄤ箣浜虹獌鐪嬪瘑鐮併�傚浜庨偅浜涘凡缁忎笉鐢ㄧ殑鐢ㄦ埛搴旂粰浜堟竻闄わ紝鏉冮檺杩囩晫鐨勭敤鎴峰簲鍙婃椂鍥炴敹鏉冮檺锛屽洖鏀舵潈闄愬彲浠ラ�氳繃鏇存柊User琛ㄧ浉搴斿瓧娈碉紝 涔熷彲浠ヤ娇鐢≧EVOKE鎿嶄綔銆�

涓嬮潰缁欏嚭鏈汉浠庡叾瀹冭祫鏂�(www.cn-java.com)鑾峰緱鐨勫甯哥敤鏉冮檺鐨勮В閲婏細

鍏ㄥ眬绠$悊鏉冮檺锛�

FILE: 鍦∕ySQL鏈嶅姟鍣ㄤ笂璇诲啓鏂囦欢銆�

PROCESS: 鏄剧ず鎴栨潃姝诲睘浜庡叾瀹冪敤鎴风殑鏈嶅姟绾跨▼銆�

RELOAD: 閲嶈浇璁块棶鎺у埗琛紝鍒锋柊鏃ュ織绛夈��

SHUTDOWN: 鍏抽棴MySQL鏈嶅姟銆�

鏁版嵁搴�/鏁版嵁琛�/鏁版嵁鍒楁潈闄愶細

ALTER: 淇敼宸插瓨鍦ㄧ殑鏁版嵁琛�(渚嬪澧炲姞/鍒犻櫎鍒�)鍜岀储寮曘��

CREATE: 寤虹珛鏂扮殑鏁版嵁搴撴垨鏁版嵁琛ㄣ��

DELETE: 鍒犻櫎琛ㄧ殑璁板綍銆�

DROP: 鍒犻櫎鏁版嵁琛ㄦ垨鏁版嵁搴撱��

INDEX: 寤虹珛鎴栧垹闄ょ储寮曘��

INSERT: 澧炲姞琛ㄧ殑璁板綍銆�

SELECT: 鏄剧ず/鎼滅储琛ㄧ殑璁板綍銆�

UPDATE: 淇敼琛ㄤ腑宸插瓨鍦ㄧ殑璁板綍銆�

鐗瑰埆鐨勬潈闄愶細ALL: 鍏佽鍋氫换浣曚簨(鍜宺oot涓�鏍�)銆�

USAGE: 鍙厑璁哥櫥褰曗�撳叾瀹冧粈涔堜篃涓嶅厑璁稿仛銆�

鐭ヨ瘑鎷撳睍锛�

Ubuntu涓嬭繙绋嬭闂甅ySQL鏁版嵁搴�

mysql -uroot -p123456聽gameTop 聽gametop800

杞浇澹版槑锛�鏈枃杞嚜

http://blog.csdn.net/ithomer/article/details/5131863

鍏虫敞涓�娉紒鍠滄涓�娉紒鏈汉鏄墠绔彍楦燂紝姝e湪鍋氳嚜宸辩殑涓汉鍗氬閭撻箯鐨勫崥瀹�锛� 浣跨敤鐨勬妧鏈� vue + koa2 + mysql + php + nginx锛�

你可能感兴趣的:(MySQL鏁版嵁搴撳父鐢ㄥ懡浠�)