linux下安裝mysql5.6-個(gè)人心得_第1頁(yè)
linux下安裝mysql5.6-個(gè)人心得_第2頁(yè)
linux下安裝mysql5.6-個(gè)人心得_第3頁(yè)
linux下安裝mysql5.6-個(gè)人心得_第4頁(yè)
linux下安裝mysql5.6-個(gè)人心得_第5頁(yè)
已閱讀5頁(yè),還剩20頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Linux系統(tǒng)上安裝mysql準(zhǔn)備工作從MySQL官網(wǎng)上分別下載mysql服務(wù)器端與客戶端包。如:MySQL-server-5.6.22-1.rhel5.x86_64MySQL-client-5.6.22-1.rhel5.x86_64并放到/opt目錄下(路徑可自行定義)1. 檢測(cè)系統(tǒng)是否安裝MySQL(1)進(jìn)入系統(tǒng)后,檢測(cè)是否安裝mysql.如:檢測(cè)是否安裝Mysql輸入#rpm -qa | grep -i mysql若已安裝過,會(huì)出現(xiàn)以下MySQL-server-5.0.22-0.i386MySQL-client-5.0.22-0.i386 (2)那么輸入以下命令刪除它:#rpm -ev

2、MySQL-server-5.0.22-0.i386# rpm -ev MySQL-client-5.0.22-0.i386 注意:1、若刪除的時(shí)候,出現(xiàn)刪除不成功,出現(xiàn)依賴的包,前提必須刪除依賴項(xiàng)。rpm -ev dovecot-1.0.7-7.el5.x86_64 2、重復(fù)安裝了類包可以采用以下參數(shù):-allmatches;刪除依賴包參數(shù):-nodepsrpm -e -allmatches -nodeps ArootGJ1-01-mysql # find / -name mysql.sock2. 安裝MySQL解壓安裝包rootlocalhost mysql# tar xvf MySQL-

3、5.6.22-1.linux_glibc2.5.i386.rpm-bundle.tar(1)第一步:安裝mysql服務(wù)端,輸入以下命令# rpm -ivh /opt/MySQL-server-5.5.15-1.linux2.6.x86_64.rpm當(dāng)出現(xiàn)如下:Preparing.# 100% 1:MySQL-server# 100% 。(省略顯示) /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h test1 password 'new-password&

4、#39; 。(省略顯示)表示MySQL安裝完成。(2)檢測(cè)mysql 3306是否安打開,輸入以下命令(如果沒有發(fā)現(xiàn)則需要重啟下mysql:service mysql restart|stop|start)# netstat -nat或者#netstat -ntpl;當(dāng)出現(xiàn)如下時(shí),表示mysql 3306端口打開Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp00 0.0.0.0:3306 0.0.0.0:* LIST

5、EN 上面顯示可以看出MySQL服務(wù)已經(jīng)啟動(dòng)。(3)安裝mysql客戶端,同理輸入以下命令# rpm -ivh /opt/ MySQL-client-5.5.15-1.linux2.6.x86_64.rpm當(dāng)出現(xiàn)如下:表示安裝成功warning: MySQL-client-5.1.7-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5 Preparing.# 100% 1:MySQL-client # 100% 顯示安裝完畢。(4) 測(cè)試連接遇到的報(bào)錯(cuò):ERROR 1045 (28000): Access denied for user &

6、#39;root''localhost' (using password: NO或者YES 方法(1)第一步mysqld_safe -user=mysql -skip-grant-tables -skip-networking & (跳過授權(quán)表進(jìn)入mysql)(2)第二步 進(jìn)入mysql:mysql u root mysql 在修改密碼:update user password=password(newpassword) where user=root;ERROR 1820 (HY000): You must SET PASSWORD before execut

7、ing this statement方法: SET PASSWORD = PASSWORD('123456');Query OK, 0 rows affected (0.03 sec)mysql> flush privileges;Query OK, 1 row affected (0.00 sec)也就是用mysql>  SET PASSWORD = PASSWORD('123456');這句話重新設(shè)置一次密碼! (*修改root密碼)rootlocalhost /#/usr/bin/mysqladmin -u root pas

8、sword 'xxxxxx'rootlocalhost /#mysql -u root p #Enter password:xxxxxx出現(xiàn)mysql>表示登陸成功!注意:如果使用空密碼無法登陸則需要進(jìn)入配置文件修改參數(shù)a修改MySQL的登錄設(shè)置: # vi /etc/f 在mysqld的段中加上一句:skip-grant-tables 例如: mysqld datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock skip-grant-tables

9、 保存并且退出vi。 b重新啟動(dòng)mysqld # /etc/init.d/mysqld restart Stopping MySQL: OK  Starting MySQL: OK  c登錄并修改MySQL的root密碼 # /usr/bin/mysql Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 to server version: 3.23.56 Type '

10、;help;' or 'h' for help. Type 'c' to clear the buffer. mysql> USE mysql ; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> UPDATE user SET Passw

11、ord = password ( 'new-password' ) WHERE User = 'root' ; Query OK, 0 rows affected (0.00 sec) Rows matched: 2 Changed: 0 Warnings: 0 mysql> flush privileges ; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye d將MySQL的登錄設(shè)置修改回來 # vi /etc/

12、f 將剛才在mysqld的段中加上的skip-grant-tables刪除 保存并且退出vi。 e重新啟動(dòng)mysqld # /etc/init.d/mysqld restart Stopping MySQL: OK  Starting MySQL: OK Work for fun,Live for love!f、登錄成功后必須先修改密碼,如下:mysql>SET PASSWORD FOR 'root''localhost' = PASSWORD('newpwd');對(duì)mysql用戶

13、設(shè)置遠(yuǎn)處訪問權(quán)限方法1、改表法:登陸mysql后,更改“mysql”數(shù)據(jù)庫(kù)里的“user”表里的“host”項(xiàng),將“l(fā)ocalhost”改“%”mysql>use mysql;mysql>update user set host ='%' where user ='root' and host=localhost;mysql>select host,user from user;mysql>FLUSH PRIVILEGES;方法2、授權(quán)法:假設(shè)允許用戶username通過密碼password從遠(yuǎn)程連接到mysql服務(wù)器mysql>G

14、RANT ALL PRIVILEGES ON *.* TO username'%' IDENTIFIED BY 'password' WITH GRANT OPTION;mysql>FLUSH PRIVILEGES;增加MySQL用戶格式:grant select on 數(shù)據(jù)庫(kù).* to 用戶名登錄主機(jī) identified by "密碼" 例1、增加一個(gè)用戶user_1密碼為123,讓他可以在任何主機(jī)上登錄,并對(duì)所有數(shù)據(jù)庫(kù)有查詢、插入、修改、刪除的權(quán)限。首先用以root用戶連入MySQL,然后鍵

15、入以下命令:mysql> grant select,insert,update,delete on *.* to user_1"%" Identified by "123" 例1增加的用戶是十分危險(xiǎn)的,如果知道了user_1的密碼,那么他就可以在網(wǎng)上的任何一臺(tái)電腦上登錄你的MySQL數(shù)據(jù)庫(kù)并對(duì)你的數(shù)據(jù)為所欲為了,解決辦法見例2。例2、增加一個(gè)用戶user_2密碼為123,讓此用戶只可以在localhost上登錄,并可以對(duì)數(shù)據(jù)庫(kù)aaa進(jìn)行查詢、插入、修改、刪除的操作(localhost指本地主機(jī),即MySQL數(shù)據(jù)庫(kù)所在的那臺(tái)主機(jī)),這樣用戶

16、即使用知道user_2的密碼,他也無法從網(wǎng)上直接訪問數(shù)據(jù)庫(kù),只能通過MYSQL主機(jī)來操作aaa庫(kù)。mysql>grant select,insert,update,delete on aaa.* to user_2localhost identified by "123"用新增的用戶如果登錄不了MySQL,在登錄時(shí)用如下命令:mysql -u user_1 -p-h 192.168.113.50(-h后跟的是要登錄主機(jī)的ip地址)      例3、用戶root用戶登陸添加一個(gè)本地用戶,名為username密碼為passwordGRANT

17、ALL PRIVILEGES ON *.* TO IDENTIFIED BY 'password' WITH GRANT OPTION;添加一個(gè)遠(yuǎn)程用戶,名為username密碼為passwordGRANT ALL PRIVILEGES ON *.* TO " IDENTIFIED BY 'password' WITH GRANT OPTION;mysql > FLUSH PRIVILEGES;好了,可以退出重新登錄,此時(shí)就得用你設(shè)置的密碼了.取消root遠(yuǎn)程登錄權(quán)限mysql>revoke all PRIVILEGES on *.* fr

18、om root'%' identified by 'newpwd'注意:如果出現(xiàn)mysql ERROR 1045 (28000): Access denied for user root'% (using password: YES) 解決:rootlocalhost mysql# /usr/local/mysql/bin/mysqld_safe -user=mysql -skip-grant-tables -skip-networking &     rootlocalhos

19、t mysql#/usr/local/mysql/ bin/mysql -u root mysql Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> update user set password=PASSWORD(123456) where user='root'Query OK, 3 rows affected (0.00 sec)Rows matched: 3 

20、 Changed: 3  Warnings: 0 mysql> flush privileges;Query OK, 0 rows affected (0.00 sec) rootlocalhost mysql# /usr/local/mysql/bin/mysql -uroot -pEnter password: * (6) 修改密碼1、 命令usr/bin/mysqladmin -u root password 'new-password'格式:mysqladmin -u用戶名 -p舊密碼

21、 password 新密碼2、例子例1:給root加個(gè)密碼123456。鍵入以下命令 :roottest1 local# /usr/bin/mysqladmin -u root password 123456注:因?yàn)殚_始時(shí)root沒有密碼,所以-p舊密碼一項(xiàng)就可以省略了。 3、 用修改后的密碼登錄roottest1 local# mysql -u root -pEnter password: (輸入修改后的密碼123456) (7) 安裝目錄數(shù)據(jù)庫(kù)目錄:/var/lib/mysql/ (安裝完后啟動(dòng)失敗,可以嘗試 shell>chown -R mysql.mysql /var/lib/m

22、ysql)配置文件:/usr/share/mysql(mysql.server命令及配置文件)相關(guān)命令:/usr/bin(mysqladmin、mysqldump等命令)(*mysql的一種安全啟動(dòng)方式:/usr/bin/mysqld_safe -user=root &)啟動(dòng)腳本:/etc/rc.d/init.d/(8) 查看修改字符編碼查看字符編碼:mysql>show variables like 'character_set_%'mysql>show variables like 'collation_%'停止mysql服務(wù)將目錄/us

23、r/share/mysql下的文件my-f拷貝到/etc/下并改名為f打開f在client和mysqld下面均加上default-character-set=utf8,并保存*mysql5.5 在mysqld下面添加參數(shù) character-set-server=utf83. 配置MySQL(1)上面都是安裝完成了,但都是默認(rèn)的,還需要很多配置。先了解下默認(rèn)安裝位置及作用 1.數(shù)據(jù)庫(kù)目錄 /var/lib/mysql/ 2、配置文件 /usr/share/mysql(mysql.server命令及配置文件) 3、相關(guān)命令 /usr/bin(mysqladmin mysqldump等命令) 4、

24、啟動(dòng)腳本 /etc/rc.d/init.d/(啟動(dòng)腳本文件mysql的目錄) 如:/etc/rc.d/init.d/mysql start/restart/stop/status(2)由于MySQL數(shù)據(jù)庫(kù)目錄占用磁盤比較大,所以我在/根目錄下建了個(gè)個(gè)目錄data,命令如下:#cd /#mkdir data(3)把數(shù)據(jù)庫(kù)移動(dòng)到data目錄中去。輸入以下命令:# mv /var/lib/mysql /data最后,進(jìn)入data目錄就會(huì)看到有一個(gè)mysql文件夾??截愅旰筮€需修改/etc/rc.d/init.d/mysql的datadir目錄值,修改結(jié)果如: basedir=datadir=/dat

25、a/mysql(4)拷貝配置文件到/etc目錄下,并命名為f(必須名為f)#cp /usr/share/mysql/my-f /etc/f這兒要注意:/usr/share/mysql/下有好幾個(gè)結(jié)尾為cnf的文件,它們的作用分別是:1.my-f是為了小型數(shù)據(jù)庫(kù)而設(shè)計(jì)的。不應(yīng)該把這個(gè)模型用于含有一些常用項(xiàng)目的數(shù)據(jù)庫(kù)。2.·my-f是為中等規(guī)模的數(shù)據(jù)庫(kù)而設(shè)計(jì)的。如果你正在企業(yè)中使用RHEL,可能會(huì)比這個(gè)操作系統(tǒng)的最小RAM需求(256MB)明顯多得多的物理內(nèi)存。由此可見,如果有那么多RAM內(nèi)存可以使用,自然可以在同一臺(tái)機(jī)器上運(yùn)行其它服務(wù)。3·my-f是為專用于一個(gè)SQL數(shù)據(jù)庫(kù)的

26、計(jì)算機(jī)而設(shè)計(jì)的。由于它可以為該數(shù)據(jù)庫(kù)使用多達(dá)512MB的內(nèi)存,所以在這種類型的系統(tǒng)上將需要至少1GB的RAM,以便它能夠同時(shí)處理操作系統(tǒng)與數(shù)據(jù)庫(kù)應(yīng)用程序。4·my-f是為企業(yè)中的數(shù)據(jù)庫(kù)而設(shè)計(jì)的。這樣的數(shù)據(jù)庫(kù)要求專用服務(wù)器和1GB或1GB以上的RAM。這些選擇高度依賴于內(nèi)存的數(shù)量、計(jì)算機(jī)的運(yùn)算速度、數(shù)據(jù)庫(kù)的細(xì)節(jié)大小、訪問數(shù)據(jù)庫(kù)的用戶數(shù)量以及在數(shù)據(jù)庫(kù)中裝入并訪問數(shù)據(jù)的用戶數(shù)量。隨著數(shù)據(jù)庫(kù)和用戶的不斷增加,數(shù)據(jù)庫(kù)的性能可能會(huì)發(fā)生變化。 (5)最后配置/etc/f文件的datadir,和mysql.sock路徑以及默認(rèn)編碼utf-8.,紅色字體標(biāo)示為修改后的。clientpassword =

27、 123456port = 3306socket = /data/mysql/mysql.sock default-character-set=utf8# Here follows entries for some specific programs # The MySQL servermysqldport = 3306socket = /data/mysql/mysql.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512

28、Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mcharacter_set_server=utf8collation-server=utf8_general_cilower_case_table_names=1character_set_client=utf8(注意linux下mysql安裝完后是默認(rèn):區(qū)分表名的大小寫,不區(qū)分列名的大小寫;lower_case_table_names = 0 0:區(qū)分大小寫,1:不區(qū)分大小寫)max_conn

29、ections=1000(設(shè)置最大連接數(shù),默認(rèn)為 151,MySQL服務(wù)器允許的最大連接數(shù)16384; )mysql default-character-set = utf8 no-auto-rehash(6)進(jìn)入/usr/bin目錄下重啟mysql服務(wù)(初始化MySQL)初始化MySQLrootlocalhost mysql# /usr/bin/mysql_install_dbrootlocalhost mysql#cd /usr/bin/mysql restart(7)登錄mysql#cd /usr/bin/mysql -u root -pEnterpassword:(直接回車,因?yàn)榈谝淮?/p>

30、為空密碼)(8)登錄成功后,修改密碼進(jìn)入>mysql環(huán)境下,輸入:> mysql> show databases;+-+| Database |+-+| information_schema | mysql | performance_schema | test |+-+4 rows in set (0.00 sec)> mysql> use mysqlDatabase changedmysql> show tables;+-+| Tables_in_mysql |+-+| columns_priv | db | event | func | general

31、_log | help_category | help_keyword | help_relation | help_topic | host | ndb_binlog_index | plugin | proc | procs_priv | proxies_priv | servers | slow_log | tables_priv | time_zone | time_zone_leap_second | time_zone_name | time_zone_transition | time_zone_transition_type | user |+-+24 rows in set

32、(0.00 sec)> mysql>update user set password=password('123456')where user='root'修改root密碼為123456最后重啟mysql,密碼生效 /usr/local/mysql/bin/mysqld_safe -user=mysql&#cd /usr/bin/mysql restart(6)MySQL安裝成功(7)執(zhí)行以下語句用來查看MySQL默認(rèn)編碼mysql> show variables like '%colla%'+-+-+| Variabl

33、e_name | Value |+-+-+| collation_connection | gb2312_chinese_ci | collation_database | utf8_general_ci | collation_server | utf8_general_ci |+-+-+3 rows in set (0.00 sec)mysql> show variables like '%char%'+-+-+| Variable_name | Value |+-+-+| character_set_client | gb2312 | character_set_c

34、onnection | gb2312 | character_set_database | utf8 | character_set_filesystem | binary | character_set_results | gb2312 | character_set_server | utf8 | character_set_system | utf8 | character_sets_dir | /usr/share/mysql/charsets/ |+-+-+8 rows in set (0.00 sec)111:有時(shí)候啟動(dòng)兩次MySQL會(huì)報(bào)錯(cuò)通過ps aux | grep mysql

35、查看啟動(dòng)進(jìn)程,然后通過kill -9 進(jìn)程編號(hào)。刪除就可以了-查看數(shù)據(jù)庫(kù)的字符集 show variables like 'character_set_%' show variables like 'collation_%' (8)MySQL查看當(dāng)前使用用戶>mysql show processlist(9) 增加用戶格式:grant select on 數(shù)據(jù)庫(kù).* to 用戶名登錄主機(jī) identified by "密碼"例1、增加一個(gè)用戶user_1密碼為123,讓他可以在任何主機(jī)上登錄,并對(duì)所有數(shù)據(jù)庫(kù)有查詢、插入、修改、刪除的權(quán)限

36、。首先用以root用戶連入MySQL,然后鍵入以下命令:mysql> grant select,insert,update,delete on *.* to user_1"%" Identified by "123"例1增加的用戶是十分危險(xiǎn)的,如果知道了user_1的密碼,那么他就可以在網(wǎng)上的任何一臺(tái)電腦上登錄你的MySQL數(shù)據(jù)庫(kù)并對(duì)你的數(shù)據(jù)為所欲為了,解決辦法見例2。例2、增加一個(gè)用戶user_2密碼為123,讓此用戶只可以在localhost上登錄,并可以對(duì)數(shù)據(jù)庫(kù)aaa進(jìn)行查詢、插入、修改、刪除的操作(localhost指本地主機(jī),即MySQL

37、數(shù)據(jù)庫(kù)所在的那臺(tái)主機(jī)),這樣用戶即使用知道user_2的密碼,他也無法從網(wǎng)上直接訪問數(shù)據(jù)庫(kù),只能通過 MYSQL主機(jī)來操作aaa庫(kù)。mysql>grant select,insert,update,delete on aaa.* to user_2localhost identified by "123"用新增的用戶如果登錄不了MySQL,在登錄時(shí)用如下命令:mysql -u user_1 -p -h 192.168.113.50 (-h后跟的是要登錄主機(jī)的ip地址)4. 卸載mysqlrootlocalhost /#rpm -qa|grep -i mysql顯示:MySQL-server-community-5.1.44-1.rhel4.i386.rp

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論