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   change   璁剧疆瀵嗙爜   mysq   export   unity   甯哥敤   

涓€銆?銆佹杩帮細
瀹樻柟缃戠珯锛歁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/ 閫夋嫨浣犺瀹夎鐨勭増鏈紱
鎶€鏈浘鐗? src=https://downloads.mariadb.org/mariadb/repositories/#distro=CentOS&distro_release=centos7-amd64--centos7&mirror=ustc-hefei&version=10.2

鎶€鏈浘鐗? src=NO.A.0002.Nginx入门概念剖析/nginx升级/降级/nginx web虚拟主机

绗竴绔?Web MVC绠€浠?鈥斺€?SpringMVC

Apicloud鈥斺€擭VTabBarAnimation鎻掍欢

leetcode鍒烽璁板綍鈥斺€斿瓧绗︿覆

涓€闃舵鈥斺€旂煡璇嗙偣鏁村悎

Java鈥斺€旈泦鍚堢粡鍏搁潰璇曢

(c)2006-2024 SYSTEM All Rights Reserved IT常识