mysql-libs-5.1.47-4.el6.i686 顯示結果說明CentOS6.0系統自帶了一個MySQL,我們需要刪除這個老版本,用root用戶執行下面語句
su -密碼:rpm -e --nodeps mysql-libs-5.1.47-4.el6.i686先切換到"root"用戶下,然后執行刪除語句,刪除之后,我們再次查看,發現已經成功刪除了CentOS6.0自帶的舊MySQL版本。在刪除MySQL的rpm后,還要進行一些掃尾操作,網上有兩種操作。(備注:我在這里兩種都沒有用到,發現系統中并沒有其他殘余的MySQL信息。)第一種善后處理:使用下面命令進行處理。rm -rf /var/lib/mysql*rm -rf /usr/share/mysql*另一種善后處理:卸載后 /var/lib/mysql 中的 /etc/my.cnf 會重命名為 my.cnf.rpmsave,/var/log/mysqld.log 會重命名為 /var/log/mysqld.log.rpmsave,如果確定沒用后就手工刪除。2)安裝MySql 服務端rpm -ivh MySQL-server-5.6.22-1.linux_glibc2.5.x86_64.rpmPReparing... ########################################### [100%]1:MySQL-server ########################################### [100%]warning: user mysql does not exist - using rootwarning: group mysql does not exist - using root2014-08-10 22:43:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2014-08-10 22:43:44 23012 [Note] InnoDB: Using atomics to ref count buffer pool pages2014-08-10 22:43:44 23012 [Note] InnoDB: The InnoDB memory heap is disabled2014-08-10 22:43:44 23012 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-08-10 22:43:44 23012 [Note] InnoDB: Memory barrier is not used2014-08-10 22:43:44 23012 [Note] InnoDB: Compressed tables use zlib 1.2.32014-08-10 22:43:44 23012 [Note] InnoDB: Using Linux native AIO2014-08-10 22:43:44 23012 [Note] InnoDB: Not using CPU crc32 instructions2014-08-10 22:43:44 23012 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-08-10 22:43:44 23012 [Note] InnoDB: Completed initialization of buffer pool2014-08-10 22:43:45 23012 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!2014-08-10 22:43:45 23012 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB2014-08-10 22:43:45 23012 [Note] InnoDB: Database physically writes the file full: wait...2014-08-10 22:43:45 23012 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB2014-08-10 22:43:46 23012 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB2014-08-10 22:43:46 23012 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02014-08-10 22:43:46 23012 [Warning] InnoDB: New log files created, LSN=457812014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer not found: creating new2014-08-10 22:43:46 23012 [Note] InnoDB: Doublewrite buffer created2014-08-10 22:43:46 23012 [Note] InnoDB: 128 rollback segment(s) are active.2014-08-10 22:43:46 23012 [Warning] InnoDB: Creating foreign key constraint system tables.2014-08-10 22:43:47 23012 [Note] InnoDB: Foreign key constraint system tables created2014-08-10 22:43:47 23012 [Note] InnoDB: Creating tablespace and datafile system tables.2014-08-10 22:43:47 23012 [Note] InnoDB: Tablespace and datafile system tables created.2014-08-10 22:43:47 23012 [Note] InnoDB: Waiting for purge to start2014-08-10 22:43:47 23012 [Note] InnoDB: 5.6.22 started; log sequence number 0A random root passWord has been set. You will find it in '/root/.mysql_secret'.2014-08-10 22:43:48 23012 [Note] Binlog end2014-08-10 22:43:48 23012 [Note] InnoDB: FTS optimize thread exiting.2014-08-10 22:43:48 23012 [Note] InnoDB: Starting shutdown...2014-08-10 22:43:50 23012 [Note] InnoDB: Shutdown completed; log sequence number 16259772014-08-10 22:43:50 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2014-08-10 22:43:50 23039 [Note] InnoDB: Using atomics to ref count buffer pool pages2014-08-10 22:43:50 23039 [Note] InnoDB: The InnoDB memory heap is disabled2014-08-10 22:43:50 23039 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-08-10 22:43:50 23039 [Note] InnoDB: Memory barrier is not used2014-08-10 22:43:50 23039 [Note] InnoDB: Compressed tables use zlib 1.2.32014-08-10 22:43:50 23039 [Note] InnoDB: Using Linux native AIO2014-08-10 22:43:50 23039 [Note] InnoDB: Not using CPU crc32 instructions2014-08-10 22:43:50 23039 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-08-10 22:43:50 23039 [Note] InnoDB: Completed initialization of buffer pool2014-08-10 22:43:50 23039 [Note] InnoDB: Highest supported file format is Barracuda.2014-08-10 22:43:50 23039 [Note] InnoDB: 128 rollback segment(s) are active.2014-08-10 22:43:50 23039 [Note] InnoDB: Waiting for purge to start2014-08-10 22:43:50 23039 [Note] InnoDB: 5.6.22 started; log sequence number 16259772014-08-10 22:43:50 23039 [Note] Binlog end2014-08-10 22:43:50 23039 [Note] InnoDB: FTS optimize thread exiting.2014-08-10 22:43:50 23039 [Note] InnoDB: Starting shutdown...2014-08-10 22:43:52 23039 [Note] InnoDB: Shutdown completed; log sequence number 1625987A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !You will find that password in '/root/.mysql_secret'.You must change that password on your first connect,no other statement but 'SET PASSWORD' will be accepted.See the manual for the semantics of the 'password expired' flag.Also, the account for the anonymous user has been removed.In addition, you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the test database.This is strongly recommended for production servers.See the manual for more instructions.Please report any problems athttp://bugs.mysql.com/The latest information about MySQL is available on the web athttp://www.mysql.comSupport MySQL by buying support/licenses athttp://shop.mysql.comNew default config file was created as /usr/my.cnf andwill be used by default by the server when you start it.You may edit this file to change server settings3)檢測 MySQL 3306 端口是否安打開。測試是否成功可運行 netstat 看 MySQL 端口是否打開,如打開表示服務已經啟動,安裝成功。MySQL 默認的端口是3306。[root@hadoopMysql]#netstat -nat Active Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 0.0.0.0:50070 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:22 0.0.0.0:* LISTENtcp 0 0 127.0.0.1:631 0.0.0.0:* LISTENtcp 0 0 127.0.0.1:25 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:50010 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:50075 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:50020 0.0.0.0:* LISTENtcp 0 0 192.168.128.129:9000 0.0.0.0:* LISTENtcp 0 0 0.0.0.0:50090 0.0.0.0:* LISTENtcp 1 0 192.168.128.129:35744 63.130.76.64:80 CLOSE_WAITtcp 0 0 192.168.128.129:34847 192.168.128.129:9000 ESTABLISHEDtcp 0 0 192.168.128.129:35770 192.168.128.129:9000 TIME_WAITtcp 0 52 192.168.128.129:22 192.168.128.1:1297 ESTABLISHEDtcp 0 0 192.168.128.129:50968 61.135.185.247:80 ESTABLISHEDtcp 0 0 192.168.128.129:9000 192.168.128.129:34847 ESTABLISHEDtcp 0 0 :::34803 :::* LISTENtcp 0 0 :::22 :::* LISTENtcp 0 0 ::1:631 :::* LISTENtcp 0 0 :::8088 :::* LISTENtcp 0 0 :::13562 :::* LISTENtcp 0 0 :::8030 :::* LISTENtcp 0 0 :::8031 :::* LISTENtcp 0 0 :::8032 :::* LISTENtcp 0 0 :::8033 :::* LISTENtcp 0 0 :::8040 :::* LISTENtcp 0 0 :::8042 :::* LISTENtcp 0 0 ::ffff:192.168.128.129:8031 ::ffff:192.168.128.12:58051 ESTABLISHEDtcp 0 0 ::ffff:192.168.128.12:58051 ::ffff:192.168.128.129:8031 ESTABLISHED4)啟動MySql 服務[root@hadoopMysql]#service mysql start Starting MySQL.......... SUCCESS!5)安裝客戶端[root@hadoopMysql]#rpm -ivh MySQL-client-5.6.22-1.linux_glibc2.5.x86_64.rpmPreparing... ########################################### [100%]1:MySQL-client ^C########################################### [100%] 安裝完成5)MySQL的幾個重要目錄。MySQL安裝完成后不像 SQL Server 默認安裝在一個目錄,它的數據庫文件、配置文件和命令文件分別在不同的目錄,了解這些目錄非常重要,尤其對于Linux的初學者,因為 Linux本身的目錄結構就比較復雜,如果搞不清楚MySQL的安裝目錄那就無從談起深入學習。a、數據庫目錄 /var/lib/mysql/b、配置文件 /usr/share/mysql(mysql.server命令及配置文件)c、相關命令 /usr/bin(mysqladmin mysqldump等命令)d、啟動腳本 /etc/rc.d/init.d/(啟動腳本文件mysql的目錄)如:/etc/rc.d/init.d/mysql start/restart/stop/status6)更改 MySQL 目錄。由于MySQL數據庫目錄占用磁盤比較大,而MySQL默認的數據文件存儲目錄為 /"var/lib/mysql",也可以把要把數據目錄移到 "/" 根目錄下的 "mysql_data" 目錄中(如果做測試用就不用移動了)。停止 MySql 服務進程:service mysql stop或者 mysqladmin -u root -p shutdownMySQL默認用戶名為"root",此處的"root"與Linux的最高權限用戶"root"不是一會兒,而且默認的用戶"root"的密碼為空,所以上圖中讓輸入密碼,直接點擊回車即可。把 "/var/lib/mysql" 整個目錄移到 "/mysql_data"mv /var/lib/mysql /mysql_data找到my.cnf配置文件如果"/etc/"目錄下沒有my.cnf配置文件,請到 "/usr/share/mysql/" 下找到 my-default.cnf 文件,拷貝其中一個合適的配置文件到 "/etc/" 并改名為 "my.cnf" 中。命令如下:cp /usr/share/mysql/my-medium.cnf /etc/my.cnf編輯MySQL的配置文件 "/etc/my.cnf"為保證MySQL能夠正常工作,需要指明"mysql.sock"文件的產生位置,以及默認編碼修改為UTF-8。用下面命令:vim /etc /my.cnf[mysqld] #下添加以下命令socket = /var/lib/mysql/mysql/mysql.sockdatadir=/mysql_data/mysql #如果你的數據存儲位置要改變的話需要在這里指定存儲目錄character-set-server=utf8lower_case_table_names=1 #(注意linux下mysql安裝完后是默認:區分表名的大小寫,不區分列名的大小寫;# lower_case_table_names = 0 0:區分大小寫,1:不區分大小寫)注意:1)最后一行,我在本地安裝的時候沒有添加此設置也可以照樣運行起來,加不加還要看你們自己了。2)還有在此配置文件還有 [client] 的一下配置 其中也可以設置socket,datadir兩個選項,我這里也沒有(此處不做配置,因為只是安裝 MySql 測試用),不知道是版本的原因還是什么,如果大家需要弄清楚這個怎么使用,那就自己先百度一下吧;3)如果你修改了數據的存儲位置目錄 ,則可以執行以下命令來修改MySQL啟動腳本 "/etc/rc.d/init.d/mysql" 最后,需要修改MySQL啟動腳本 /etc/rc.d/init.d/mysql,修改 datadir=/mysql_data/mysql。vim /etc/rc.d/init.d/mysql7)重新啟動MySQL服務service mysql start發生錯誤:Starting MySQL ERROR! The server quit without updataing PID file....經百度后解決方法是:vi /etc/selinux/config把 SELINUX=enforcing 改為SELINUX=disabled后存盤退出重啟機器試試,必須要重啟,很關鍵。千辛萬苦重啟后盼望著能管用,結果 服務器啟動不了了。。。。。顯示錯誤:Kernel panic - not syncing: Attempted to kill init PS:太糟心了,安裝個MySQL 費這么大的勁。。。經過百度又找到新的解決文案:解決辦法系統啟動的時候,按下 ‘e’ 鍵進入 grub 編輯界面,編輯 grub 菜單,選擇 “kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/vogroup00/logvol00 rhgb quiet” 一欄,按‘e’鍵進入編輯,在末尾增加enforcing=0,即:kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/vogroup00/logvol00 rhgb quietenforcing=0按‘b’鍵繼續引導,OK順利前進。好吧終于順利進入到 Linux 系統,啟動MySQL 服務:service mysql start又提示錯誤:MySQL:StartingMySQL…..ERROR!TheserverquitwithoutupdatingPIDfile解決辦法是因為 MySQL 沒有初始化表/usr/bin/mysql_install_db --user=mysqlservice mysql start就可以重啟MySQL 服務了。PS:安裝個MySql 著實不容易啊。。。。。8)修改登錄密碼MySQL默認沒有密碼,安裝完畢增加密碼的重要性是不言而喻的。修改前,直接登錄檢查 MySql 端口是否開啟:[root@hadoop ~]#netstat -ntlp | grep 3306tcp 0 0 :::3306 :::* LISTEN 5052/mysqld $:mysql報錯:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)發現 與設置 MySql 服務器的socket位置不一樣。改一下 /etc/my.cn修改socket = /var/lib/mysql/mysql.sock --保存;再次進入:[root@hadoop init.d]# mysql又報錯。。。ERROR 1045 (28000): access denied for user 'root'@'localhost' (using password: NO)百度一下解決方法:[root@hadoop~]#mysqld_safe --user=mysql --skip-grant-tables --skip-networking & mysql -u root mysql再次進入:[root@hadoop ~]# mysqlWelcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 2Server version: 5.6.22 MySQL Community Server (GPL)Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.mysql>OK 了總算安裝成功了。。。在沒有添加密碼前,直接輸入"mysql"就能登錄到MySQL數據庫里。修改登錄密碼:[root@hadoop~]mysqladmin -u root password 'root'格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼如果已經連接上了 MySql 可以使用下面語句 :mysql>use mysql;mysql>UPDATE user SET Password=PASSWORD('root') where USER='root';Query OK, 4 rows affected (0.04 sec)Rows matched: 4 Changed: 4 Warnings: 0修改成功;本文參考博客:http://www.CUOXin.com/xia520pi/archive/2012/06/12/2546261.html多謝蝦皮工作室新聞熱點
疑難解答