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锛�