NO.A.0002鈥斺€攎ysql/mariadb5.5.65鈥斺€攜um瀹夎/閰嶇疆
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NO.A.0002鈥斺€攎ysql/mariadb5.5.65鈥斺€攜um瀹夎/閰嶇疆相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/ibdata1' title='ibdata1'>ibdata1
瀹樻柟缃戠珯锛歁ySQL瀹樼綉锛?a href="https://www.mysql.com/" rel="nofollow">https://www.mysql.com/
mariadb瀹樼綉锛?a href="https://mariadb.com/" rel="nofollow">https://mariadb.com/
瀹樻柟鏂囨。锛歁ySQL锛?a href="https://dev.mysql.com/doc/" rel="nofollow">https://dev.mysql.com/doc/
Mariadb锛?a href="https://mariadb.com/kb/en" rel="nofollow">https://mariadb.com/kb/en
鐗堟湰婕斿彉锛歁ySQL锛?.1锛坈entos6.x锛夆€斺€?gt;5.5鈥斺€?gt;5.6鈥斺€?gt;5.7
MariaDB锛?.5锛坈entos7.x)鈥斺€?gt;10.0鈥斺€?gt;10.1鈥斺€?gt;10.2鈥斺€?gt;10.3
MySQL鐗堟湰锛?br/>MySQL Community Server 绀惧尯鐗堟湰锛屽紑婧愬厤璐癸紝浣嗕笉鏀寔瀹樻柟鎶€鏈敮鎸併€?br/>MySQL Enterprise Edition 浼佷笟鐗堟湰锛岄渶浠樿垂鍙互浣跨敤30澶┿€?br/>MySQL Cluster 闆嗙兢鐗堬紝寮€婧愬厤璐癸紝鍙皢鍑犱釜MySQL Server灏佽鎴愪竴涓猻erver銆?br/>MySQL Cluster CGE 楂樼骇闆嗙兢鐗堬紝闇€浠樿垂銆?br/>2銆乵ariadb鐨勫畨瑁呮柟寮忥細
婧愪唬鐮侊細缂栬瘧瀹夎
浜岃繘鍒舵牸寮忕殑绋嬪簭鍖咃紝灞曞紑鑷崇壒瀹氳矾寰勶紝骞剁粡杩囩畝鍗曢厤缃悗鍗冲彲浣跨敤
绋嬪簭鍖呯鐞嗗櫒绠$悊鐨勭▼搴忓寘锛?br/>centos涓嬪畨瑁卪ariadb瀹樻柟鏁欑▼锛?a href="https://downloads.mariadb.org/mariadb/repositories/" rel="nofollow">https://downloads.mariadb.org/mariadb/repositories/
浜屻€乵ysql/mariadb.server瀹夎鏁欑▼锛?/p>
1銆乧entos6.5涓嬪畨瑁卪ysql-server
//1銆佹煡璇ysql-server骞跺畨瑁卪ysql杞欢
[root@localhost ~]# yum info mysql-server //鏌ヨmysql-server瀹夎鍖?Name : mysql-server
Arch : x86_64
Version : 5.1.73
Release : 8.el6_8
Size : 8.6 M
//2銆佸畨瑁卪ysql-server绋嬪簭
[root@localhost ~]# yum install -y mysql-server
//瀹夎centos6.x閲岄潰鑷甫mysql-server鐗堟湰锛岃嫢闇€瑕佹柊鐗堟湰锛屽彲浠ュ幓閰嶇疆yum婧愶紝涓嬫枃鏈夐厤缃暀绋?Installed:
mysql-server.x86_64 0:5.1.73-8.el6_8
Dependency Installed:
mysql.x86_64 0:5.1.73-8.el6_8 perl-DBD-MySQL.x86_64 0:4.013-3.el6
//3銆佹煡鐪媘ysql-server瀹夎鏄惁鎴愬姛
[root@localhost ~]# rpm -ql mysql-server
/etc/rc.d/init.d/mysqld //鍚姩鏂囦欢
/usr/libexec/mysqld //鏁版嵁搴撶殑涓荤▼搴忋€佷簩杩涘埗绋嬪簭
/var/lib/mysql //灏嗘潵瀛樻斁鐢ㄦ埛鏁版嵁鐨勬暟鎹洰褰? /var/log/mysqld.log //鏃ュ織鏂囦欢鍖? /var/run/mysqld
//4銆佽缃▼搴忓瘑鐮佸畨鍏?[root@localhost ~]# mysql_secure_installation
//5銆佽缃紑鏈鸿嚜鍚姩
[root@localhost ~]# chkconfig --list mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on
3:on 4:on 5:on 6:off
//6銆佸惎鍔╩ysqld绋嬪簭
[root@localhost ~]# service mysqld start
[root@localhost ~]# ss -tnl //鏌ョ湅瀹冪殑绔彛鍙?LISTEN 0 50 *:3306
//7銆佹煡鐪媘ysql閰嶇疆鏂囦欢
[root@localhost ~]# ll /var/lib/mysql/ //绗竴娆″惎鍔ㄧ殑鏃跺€欎細鐢熸垚鏁版嵁搴撴枃浠躲€?
total 20488
-rw-rw---- 1 mysql mysql 10485760 Nov 5 18:04 ibdata1
-rw-rw---- 1 mysql mysql 5242880 Nov 5 18:04 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Nov 5 18:04 ib_logfile1
drwx------ 2 mysql mysql 4096 Nov 5 18:04 mysql
srwxrwxrwx 1 mysql mysql 0 Nov 5 18:04 mysql.sock
//mysql.sock涓昏鐢ㄤ簬鏈湴閫氳
drwx------ 2 mysql mysql 4096 Nov 5 18:04 test
[root@localhost ~]# date //閫氳繃鏃堕棿鍙互鐪嬪嚭鏉?Thu Nov 5 18:07:13 CST 2020
//8銆佸埄鐢╩ysql瀹㈡埛绔伐鍏峰幓閾炬帴mysql鏁版嵁搴?[root@localhost ~]# which mysql
/usr/bin/mysql
[root@localhost ~]# rpm -qf /usr/bin/mysql //灞炰簬鍝釜鍖?mysql-5.1.73-8.el6_8.x86_64
//9銆乵ysql瀹㈡埛绔笅甯哥敤鎿嶄綔锛?[root@localhost ~]# mysql //榛樿鏄棤瀵嗙爜鐧诲綍锛屾湭璁剧疆瀵嗙爜榛樿鏃犲瘑鐮併€?Type 鈥榟elp;鈥?or 鈥榎h鈥?for help. Type 鈥榎c鈥?to clear the current input statement.
//杈撳叆鈥渉elp;鈥濇垨鈥淺h鈥濊姹傚府鍔┿€傞敭鍏モ€榎c鈥樹互娓呴櫎褰撳墠杈撳叆璇彞銆?
mysql> show databases; //鏌ヨ褰撳墠绯荤粺涓墍鏈夋暟鎹簱鍒楄〃
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> system hostname //mysql涓嬪彲浠ユ墽琛宭inux鍛戒护
localhost.localdomain
mysql> status //鏌ョ湅绯荤粺鐨勭姸鎬佷俊鎭?Current database: //褰撳墠涓嶅湪浠讳綍鏁版嵁搴撻噷
Current user: root@localhost
//褰撳墠涓庢暟鎹簱杩炴帴鏃剁殑鐢ㄦ埛鍚? ,鏄疢ySQL璐︽埛鑷韩鐨勭敤鎴凤紱鎴戞槸鍦ㄦ湰鏈虹敤root鐧诲綍鍒版暟鎹簱涓?
mysql> use mysql //鍒囨崲鍒癿ysql鏁版嵁搴?Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> status
Current database: mysql //褰撳墠鍦╩ysql鏁版嵁搴撲腑
Current user: root@localhost
mysql> s // s涔熷彲浠ヨ〃绀轰负status锛屾槸status鐨勭畝鍐?mysql>quit //閫€鍑簃ysql瀹㈡埛绔?/code>
2銆乧entos7.x涓嬪畨瑁卪ariadb-server鏈嶅姟锛?/p>
//1銆佸畨瑁呴儴缃瞞ariadb-server
[root@localhost ~]# yum install mariadb-server -y
Installing:
mariadb-server x86_64 1:5.5.65-1.el7 //鏈嶅姟鍣ㄧ鍖?Installing for dependencies:
mariadb x86_64 1:5.5.65-1.el7 //瀹㈡埛绔寘
//2銆佹煡鐪媘ysql瀹夎璺緞锛屽強閮ㄧ讲鐨勭増鏈?[root@localhost bin]# which mysql
/usr/bin/mysql
[root@localhost bin]# rpm -qf /usr/bin/mysql
mariadb-5.5.65-1.el7.x86_64
//3銆佺櫥褰昺ysql瀹㈡埛绔?[root@localhost ~]# mysql //鏈嶅姟娌℃湁鍚姩锛沵ysql.sock鏂囦欢涓嶄細鐢熸垚
ERROR 2002 (HY000): Can鈥榯 connect to local MySQL server through socket 鈥?/var/lib/mysql/mysql.sock鈥?[root@localhost ~]# rpm -ql mariadb-server //鏌ョ湅mariadb鍖呭惈鐨勫寘鍒楄〃
/usr/lib/systemd/system/mariadb.service //鏈嶅姟鍚嶏紝鎰忓鐨勬垜浠悗鏈熸搷浣滄椂浣跨敤mariadb.service
/var/lib/mysql
/var/log/mariadb
/var/log/mariadb/mariadb.log
/var/run/mariadb
//4銆佸惎鍔╩ariad.service
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# ss -tunlp |grep mysqld
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=115344,fd=14))
root@localhost ~]# pstree -p //mysql宸ヤ綔鍘熺悊鏄熀浜庡崟杩涚▼澶氱嚎绋?[root@localhost ~]# ll /var/lib/mysql/ //瀛樻斁鐨勫氨鏄暟鎹簱鐨勫垪琛?total 28700
drwx------ 2 mysql mysql 4096 Nov 5 21:56 mysql
srwxrwxrwx 1 mysql mysql 0 Nov 5 21:56 mysql.sock
drwx------ 2 mysql mysql 4096 Nov 5 21:56 performance_schema //鍦ㄥ唴瀛橀噷铏氭嫙鐨勬暟鎹簱
drwx------ 2 mysql mysql 6 Nov 5 21:56 test
//5銆乵ysql鏁版嵁搴撲竴鑸搷浣滐紱
MariaDB [(none)]> show databases; //鏌ョ湅鏀寔鐨勬暟鎹簱鍒楄〃
+--------------------+
| Database |
+--------------------+|
| mysql |
//鍒╃敤澶嶅埗鐨勬柟娉曞厠闅嗕竴涓暟鎹簱
[root@localhost ~]# cd /var/lib/mysql/ //杩涘叆鍒癿ysql鏁版嵁搴撳垪琛ㄦ枃浠跺す
[root@localhost mysql]# cp -a mysql mysqlclone //鍏嬮殕涓€涓猰ysql鏁版嵁搴搈ysqlclone
MariaDB [(none)]> show databases; //姝ゆ椂鍙互鐪嬪埌mysqlclone鏁版嵁搴?+--------------------+
| Database |
+--------------------+|
| mysql |
| mysqlclone
娉細鍏嬮殕鎶€鏈?//姝ゆ柟娉曚篃鍙互鐢ㄤ綔鏁版嵁搴撳浠界殑鏃跺€欐柟妗堬紝涓€绉嶅浠芥墜娈?//浣嗚纭繚鏁版嵁搴撶殑涓€鑷存€э紝鏁版嵁瀹屾暣鎬э紝纭繚鍚屼竴鏃堕棿鐐圭殑涓€涓枃浠?/code>
3銆乵ysql鏁版嵁搴撶殑甯哥敤鎿嶄綔锛?/p>
MariaDB [(none)]> use mysqlclone //use鎶婂綋鍓嶈闂殑鏁版嵁搴撳垏鎹㈠埌鐩爣鏁版嵁搴?Database changed
MariaDB [mysqlclone]>
MariaDB [mysqlclone]> show tables; //鏌ョ湅杩欎釜鏁版嵁搴撲腑鏈夊摢浜涜〃
MariaDB [mysqlclone]> select * from user; //鏌ヨuser杩欎釜琛ㄩ噷鐨勫唴瀹癸紱
MariaDB [mysqlclone]> select * from userG //鍔燶G琛ㄧず妯潃寰€涓嬪啓
MariaDB [mysqlclone]> drop database mysqlclone; //鍒犳帀鏁版嵁搴搈ysqlclone
Query OK, 24 rows affected (0.07 sec)
MariaDB [mysqlclone]> drop tables mysqlclone锛? //鍒犳帀鏁版嵁搴撻噷鐨勮〃
MariaDB [(none)]> system id
uid=0(root) gid=0(root) groups=0(root)
MariaDB [(none)]> select user(); //鏌ョ湅褰撳墠鐧诲綍鐨勭敤鎴?MariaDB [mysql]> select user,password,host from user; //鏌ョ湅鏈嶅姟鍣ㄤ腑鍒涘缓鐨勭敤鎴蜂俊鎭?+------+----------+-----------------------+
| user | password | host |
+------+----------+-----------------------+
| root | | localhost | //瀵嗙爜鏄┖鐨?| root | | localhost.localdomain |
| root | | 127.0.0.1 |
| root | | ::1 |
| | | localhost |
| | | localhost.localdomain |
+------+----------+-----------------------+
6 rows in set (0.00 sec)
4銆佽缃甿ysql鏁版嵁搴撶殑瀵嗙爜瀹夊叏锛?/p>
//1銆佹墽琛岀郴缁熻嚜甯︾殑瀹夊叏鑴氭湰
[root@localhost ~]# which mysql_secure_installation
/usr/bin/mysql_secure_installation
[root@localhost ~]# mysql_secure_installation
Enter current password for root (enter for none): //杈撳叆褰撳墠root璐﹀彿鐨勫彛浠わ紝娌℃湁鍙d护鐩存帴鍥炶溅
Set root password? [Y/n] y //鏄惁璁剧疆root璐﹀彿鐨勫瘑鐮?New password: //鏂板瘑鐮?
Re-enter new password: //鍐嶆杈撳叆瀵嗙爜
Remove anonymous users? [Y/n] y //鏄惁鍒犻櫎鍖垮悕璐﹀彿
Disallow root login remotely? [Y/n] n //鏄惁绮捐嚧root璐﹀彿杩滅▼鐧诲綍
Remove test database and access to it? [Y/n] y //鏄惁鍒犻櫎娴嬭瘯鏁版嵁搴?Reload privilege tables now? [Y/n] //鍔犺浇鐗规潈琛ㄤ负鐨勫氨鏄浣犲垰鎵嶇殑璁剧疆鐢熸晥
[root@localhost ~]# mysql -uroot -p123456 //鐧诲綍mysql鏁版嵁搴?MariaDB [(none)]> use mysql
MariaDB [mysql]> select user,host,password from user; //mysql鏁版嵁搴撲腑鏌ョ湅鐢ㄦ埛鐨勪俊鎭〃
+------+-----------------------+-------------------------------------------+
| user | host | password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | localhost.localdomain | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | ::1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------------------+-------------------------------------------+
4 rows in set (0.00 sec)
娉細
//mysql涓嬬敤鎴峰悕鏄湁涓ら儴鍒嗙粍鎴愶紱user=username@host 鈥?root | localhost 鈥?杩欐槸涓€涓处鍙凤紱
// host琛ㄧず浣犱粠閭e彴鐢佃剳涓婄櫥褰曪紱
// 127.0.0.1 榛樿鎯呭喌涓嬬櫥褰昺ysql涓绘満鐨刬p鍦板潃锛岄粯璁ゆ儏鍐典笅涓嶅厑璁歌繙绋嬬櫥褰曘€?// 涓婇潰鐨?涓处鍙烽兘鏄垜浠湰鏈虹殑锛岃繙绋嬩富鏈烘槸杩炰笉涓婃潵鐨勩€?// 杩滅▼涓绘満鎯宠繛鍒拌繖鍙版湇鍔″櫒鐨刴ysql鏁版嵁搴擄紝
[root@localhost ~]# mysql -uroot -p123456 -h 192.168.1.58
//姝ゆ椂杩樻槸杩炰笉浜嗭紝闇€瑕佸湪mysql鏈嶅姟鍣ㄤ笂鎺堟潈
5銆乵ariadb瀹㈡埛绔▼搴忓父鐢ㄦ搷浣滐細
瀹㈡埛绔▼搴忥細
mysql锛氫氦浜掑紡鐨凜LI宸ュ叿
mysqldump锛氬浠藉伐鍏凤紝鍩轰簬MySQL鍗忚鍚慚ySQLd鍙戣捣鏌ヨ璇锋眰锛屽苟灏嗘煡寰楃殑鎵€鏈夋暟鎹浆鎹㈡垚insert绛夊啓鎿嶄綔璇彞淇濆瓨鏂囨湰鏂囦欢涓€?br/>mysqladmin锛氬熀浜巑ysql鍗忚绠$悊mysqld
mysqlimport锛氭暟鎹鍏ュ伐鍏?br/>myIsam瀛樺偍寮曟搸鐨勭鐞嗗伐鍏凤細
myisamchk锛氭鏌yisam搴?br/>myisampack锛氭墦鍖卪yisam琛紝鍙
鏈嶅姟鍣ㄧ绋嬪簭锛?br/>mysqld_safe
mysqld
mysqld_multi锛氬瀹炰緥锛岀ず渚嬶細mysqld_multi --example
//甯哥敤鎿嶄綔锛?[root@localhost ~]# ps -aux //鍙互鏌ョ湅鍒颁笂闈袱涓湇鍔$绋嬪簭
mysql 115182 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 115344 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql
[root@localhost ~]# getent passwd mysql //鏌ョ湅mysql鐨勪俊鎭?mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin // /var/lib/mysql瀹冪殑瀹剁洰褰曪紱
[root@localhost ~]# rpm -q --scripts mariadb-server //鏌ョ湅瀹冨畨瑁呯▼搴忕殑鏃跺€欎互浠€涔堟柟寮?[root@localhost ~]# which mysqld_multi //鏌ョ湅璇ョ▼搴?/usr/bin/mysqld_multi
[root@localhost ~]# rpm -qf /usr/bin/mysqld_multi //姝ょ▼搴忓疄鐜板瀹炰緥锛?mariadb-server-5.5.65-1.el7.x86_64
5.1銆佺敤鎴疯处鍙凤細br/>mysql鐢ㄦ埛璐﹀彿鐢变袱閮ㄥ垎缁勬垚锛氣€楿SERNAME鈥楡HOST鈥橈紱璇存槑锛欻OST闄愬埗姝ょ敤鎴峰彲閫氳繃鍝簺杩滅▼涓绘満杩炴帴MySQL鏈嶅姟鍣?br/鏀寔浣跨敤閫氶厤绗︼細%鍖归厤浠绘剰闀垮害鐨勪换鎰忓瓧绗?72.16.0.0/255.255.0.0鎴?72.16.%.%锛? 鍖归厤浠绘剰鍗曚釜瀛楃
5.2銆丮ySQL瀹㈡埛绔娇鐢ㄦā寮忥細
浜や簰寮忔ā寮忥細鍙繍琛屽懡浠ゆ湁涓ょ被锛?br/>瀹㈡埛绔懡浠わ細h锛歨elp u:use s:status !锛歴ystem //MySQL瀹㈡埛绔嚜韬殑鍛戒护锛屽氨鏄湪鏁版嵁搴撲腑 h鎴栬€匼help鍙互鏌ヨ鍒扮殑鍛戒护锛岄兘灞炰簬瀹㈡埛绔懡浠わ紝涓嶉渶瑕佸姞鍒嗗彿銆?br/>鏈嶅姟鍣ㄧ鍛戒护锛歋QL锛岄渶瑕佽鍙ョ粨鏉熺锛? //鏈嶅姟鍣ㄧ鍛戒护闇€瑕佸姞鍒嗗彿銆?br/>鑴氭湰妯″紡锛?br/>mysql -uUSERNAME -PASSWORD < /path/somefile.sql
mysql> source /path/from/somefile.sql
//鍒涘缓鏁版嵁搴擄細
MariaDB [(none)]> create database testdb;
MariaDB [(none)]> show databases锛?| testdb |
MariaDB [(none)]> ! ls /var/lib/mysql //鍦∕ySQL鏁版嵁搴撲箣涓嬫墽琛宭inux鍛戒护
testdb
MariaDB [(none)]> ! ls /var/lib/mysql/testdb
db.opt
//鏂规硶涓€锛氫氦浜掑紡鐨勬柟娉?[root@localhost ~]# cat > test.sql //鍑嗗閰嶇疆鏂囦欢
create database testdb2;
show databases;
^C
[root@localhost ~]# cat test.sql
create database testdb2;
show databases;
//鏂规硶浜岋細浠ラ噸瀹氬悜鐨勬柟寮?[root@localhost ~]# mysql -uroot -p123456 <test.sql
//浠ラ噸瀹氬悜鐨勬柟寮忓幓鎵ц鍛戒护锛岀浉褰撲簬鎵ц涓€涓剼鏈紱
Database
information_schema
mysql
performance_schema
testdb
testdb2
//鏂规涓夛細浠ource鍛戒护鍘诲垱寤?MariaDB [(none)]> source test.sql
+--------------------+
| Database |
+--------------------+
| testdb |
| testdb2 |
| testdb3 |
+--------------------+
6 rows in set (0.00 sec)
5.3銆乵ariadb鏈嶅姟鍣ㄦ彁绀虹鏇存敼
//mariadb鏈嶅姟鍣ㄦ彁绀虹鏇存敼锛?//鏂规涓€锛?MariaDB [(none)]> prompt u@[D]
:m:s-> //鏇存敼褰撳墠鐨勭敤鎴锋彁绀轰俊鎭紱涓€娆℃€х殑锛岄噸鏂扮櫥鍏ヤ細涓㈠け
PROMPT set to 鈥榎u@[D]
:m:s->鈥?root@[Fri Nov 6 21:40:24 2020] 09:40:24->
//鑻ユ兂闀挎湡淇濆瓨锛岄渶瑕佷繚瀛樺埌閰嶇疆鏂囦欢涓€?//鏂规浜岋細
[root@localhost ~]# ls /etc/my.cnf.d/
client.cnf //閽堝鍏ㄥ眬鐨勯厤缃?mysql-clients.cnf //閽堝MySQL杩欎釜鏁版嵁搴撻厤缃?server.cnf //閽堝鏈嶅姟鍣ㄧ殑閰嶇疆
[root@localhost ~]# vim /etc/my.cnf.d/mysql-clients.cnf
prompt=(\u@\h) [\d]>(root@localhost) [(none)]> //鐧诲綍鏁版嵁搴撴煡鐪嬬姸鎬?
//鏂规涓夛細
[root@localhost ~]# vim /etc/profile.d/mysql.sh
export MYSQL_PS1="(u@h) [d]> "
[root@localhost ~]# . /etc/profile.d/mysql.sh
(root@localhost) [(none)]>
5.4銆丮ySQL瀹㈡埛绔父鐢ㄩ€夐」锛?/p>
MySQL瀹㈡埛绔彲鐢ㄩ€夐」锛? -A --no-auto-rehash 绂佹琛ュ叏
-u --user= 鐢ㄦ埛鍚嶏紝榛樿鏄痳oot
-h -- host= 鏈嶅姟鍣ㄤ富鏈猴紝榛樿涓簂ocalhost
-p --password= 鐢ㄦ埛瀵嗙爜锛屽缓璁娇鐢?p榛樿涓虹┖瀵嗙爜
-P --port= 鏈嶅姟鍣ㄧ鍙o紝
-S --sockt= 鎸囧畾杩炴帴socket鏂囦欢璺緞
-D --database= 鎸囧畾榛樿鏁版嵁搴? -C --compress= 鍚敤鍘嬬缉
-e --鈥淪QL鈥? 鎵цSQL鍛戒护
-V -- version= 鏄剧ず鐗堟湰淇℃伅
-v --verbose= 鏄剧ず璇︾粏淇℃伅
--prin-defaults 鑾峰彇绋嬪簭榛樿浣跨敤鐨勯厤缃?
(root@localhost) [(none)]> s //鍙互鏌ョ湅鍒板綋鍓嶆暟鎹簱sock鏂囦欢鐨勫湴鍧€
UNIX socket: /var/lib/mysql/mysql.sock
[root@localhost ~]# mysql -uroot -p123456 -D testdb //鐧诲綍鏃跺彲浠ョ洿鎺ユ寚瀹氬埌testdb鏁版嵁搴撲腑-D閫夐」
(root@localhost) [testdb]>
[root@localhost ~]# mysql -uroot -p123456 -e "show databases;" //鍦ㄧ櫥褰曠殑鏃跺€欐墽琛屽懡浠? -e閫夐」
+--------------------+
| testdb2 |
| testdb3 |
+--------------------+
[root@localhost ~]# mysql -uroot -p123456 -V //鏌ョ湅鐗堟湰淇℃伅
mysql Ver 15.1 Distrib 5.5.65-MariaDB, for Linux (x86_64) using readline 5.1
6銆乵ysql.sock鏂囦欢淇℃伅锛?br/>socket鍦板潃锛?br/>鏈嶅姟鍣ㄧ洃鍚殑涓ょsocket鍦板潃锛?br/>ip socket锛氱洃鍚湪tcp鐨?306绔彛锛屾敮鎸佽繙绋嬮€氫俊
unix sock锛氱洃鍚湪sock鏂囦欢涓婏紝浠呮敮鎸佹湰鏈洪€氳 濡傦細/var/lib/mysql/mysql.sock锛? 璇存槑锛歨ost涓簂ocalhost锛?27.0.0.1鏃惰嚜鍔ㄤ娇鐢║nix sock
鎵ц鍛戒护锛?br/>杩愯MySQL鍛戒护锛氶粯璁ょ┖瀵嗙爜鐧诲綍
mysql>use mysql
mysql>select use(); 鏌ョ湅褰撳墠鐢ㄦ埛
mysql>SELECT User,Host,Password FROM user;
鐧诲綍绯荤粺锛? mysql -uroot -p
瀹㈡埛绔懡浠わ細 鏈湴鎵ц
mysql > help
姣忎釜鍛戒护閮芥湁瀹屾暣褰㈠紡鍜岀畝鍐欐牸寮?br/>mysql> status 鎴?
鏈嶅姟鍣ㄧ鍛戒护锛? 閫氳繃mysql鍗忚鍙戝線鏈嶅姟鍣ㄦ墽琛屽苟鍙栧洖缁撴灉
姣忎釜鍛戒护閮藉繀椤荤粨鏉熺鍙凤紱榛樿涓哄垎鍙?br/>SELECCT VERSION();
[root@localhost ~]# cat /etc/my.cnf
[mysqld] //涓昏瀛樻斁鐫€鎴戜滑鏈嶅姟鍣ㄧ鐨勯厤缃?datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid //杩涚▼閰嶇疆鍦板潃
[root@localhost ~]# cat /var/run/mariadb/mariadb.pid
10682 //鍙杩涚▼璧锋潵锛屽氨浼氱敓鎴愪竴涓繘绋嬫枃浠?/code>
7銆佹湇鍔″櫒绔厤缃細
鏈嶅姟鍣ㄧ锛坢ysqld锛夛細宸ヤ綔鐗瑰緛鏈夊绉嶉厤缃柟寮忥紱
1銆佸懡浠よ閫夐」锛?br/>2銆侀厤缃枃浠讹紝绫籭ni鏍煎紡
3銆侀泦涓紡鐨勯厤缃紝鑳藉涓簃ysql鐨勪釜搴旂敤绋嬪簭鎻愪緵閰嶇疆淇℃伅
[mysqld] //鏈嶅姟鍣ㄧ閰嶇疆
[mysqld_safe] //鏈嶅姟鍣ㄧ閰嶇疆
[mysqld_multi] //澶氳繘绋嬨€佸绾跨▼閰嶇疆
[mysql] //MySQL銆佹暟鎹簱閰嶇疆锛涘鎴风
[mysqldump] //澶囦唤閰嶇疆
[server] //鏈嶅姟鍣ㄧ閰嶇疆
[client] //瀹㈡埛绔厤缃?br/>鏍煎紡锛歱arameter = value
璇存槑锛歘鍜?鐩稿悓
0锛孫FF锛孴RUE鎰忎箟鐩稿悓锛?锛孫N锛孎ALSE鎰忎箟鐩稿悓銆?br/>7.1銆侀厤缃枃浠讹細鍚庨潰瑕嗙洊鍓嶉潰鐨勯厤缃枃浠讹紝椤哄簭濡備笅锛氾紙浠庡悗鍚戝墠闈㈣鐩栧紡锛?/p>
[root@localhost ~]# /etc/my.cnf //Global閫夐」锛涜〃绀烘墍鏈夊疄渚?锛涙垜浠竴鑸啓鍦ㄦ浣嶇疆
鎴栬€?etc/my.cnf.d涓嬩篃鍙互锛屽洜涓?etc/my.cnf鍖呭惈/etc/my.cnf.d鏂囦欢
/etc/mysql/my.cnf //Global鍏ㄥ眬閫夐」 鍏ㄥ眬鎬х殑璁剧疆
SYSCONFDIR/my.cnf //Global閫夐」
$MYSQL_HOME/my.cnf //Server-specific 閫夐」 鐗瑰畾鏈嶅姟鍣ㄧ殑璁惧畾
--defaults-extra-file=path
~/my.cnf // User-specific閫夐」 鐗瑰畾鐢ㄦ埛涓嬭瀹氱殑
//鑾峰彇鍙敤鍙傛暟鍒楄〃锛? mysqld --help -verbose
mysqld --print-defaults 鑾峰彇榛樿璁剧疆
8銆丮ariadb閰嶇疆锛氫睛鍚?306/tcp绔彛鍙互鍦ㄧ粦瀹氭湁涓€涓垨鍏ㄩ儴鎺ュ彛IP涓婏紝
vim /etc/my.cnf
[mysqld]
skip-networking=1 鍏抽棴缃戠粶杩炴帴锛堣繙绋嬩笉鍙互杩炴帴锛屽彧鑳芥湰鍦拌繛鎺ワ級锛屽彧渚﹀惉鏈湴瀹㈡埛绔紝鎵€鏈夊拰鏈嶅姟鍣ㄧ殑浜や簰閮介€氳繃涓€涓猻ocket瀹炵幇锛宻ocket鐨勯厤缃瓨鏀惧湪/var/lib/mysql/mysql.sock)鍙湪/etc/my.cnf淇敼銆?/p>
[root@localhost ~]# vim /etc/my.cnf
skip-networking=1 //鍦ㄨ繖涓鍙ュ潡閲屽姞涓妔kip-networking=1閲嶅惎鏈嶅姟
[root@localhost ~]# ss -antl //鏌ョ湅姝ゆ椂鎵句笉鍒皌cp鐨?306绔彛
[root@localhost ~]# mysql -uroot -p123456 //杩樻槸鍙互杩炰笂鏁版嵁搴擄紝鍥犱负姝ゆ椂瀹冧笉璧皌cp鐨?306绔彛锛? 瀹冭蛋鐨勬槸鏈湴鐨剆ock鏂囦欢锛?/code>
涓夈€佸湪涓嶅悓鎿嶄綔绯荤粺涓嬶紝閰嶇疆鎸囧畾鐗堟湰鐨刴ysql/mariadb绋嬪簭锛?br/>鏍规嵁瀹樼綉鏁欑▼锛岄厤缃畼缃憏um婧愬湴鍧€锛?br/>1銆佸寘涓嬭浇鍦板潃锛?a href="https://downloads.mariadb.org/mariadb/10.2.35/" rel="nofollow">https://downloads.mariadb.org/mariadb/10.2.35/ 閫夋嫨浣犺瀹夎鐨勭増鏈紱
https://downloads.mariadb.org/mariadb/repositories/#distro=CentOS&distro_release=centos7-amd64--centos7&mirror=ustc-hefei&version=10.2
NO.A.0002.Nginx入门概念剖析/nginx升级/降级/nginx web虚拟主机