CentOS 6.3安裝MySQL 5.5

來源:互聯網
上載者:User

1.下載MySQL

我下載的版本:mysql-5.5.22.tar.gz

2.安裝之前先卸載CentOS內建的MySQL
[root@localhost ~]# yum remove mysql

3.編譯安裝Cmake
下載cmake源碼包:http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

從共用目錄移至usr目錄
[root@localhost ~]# mv /mnt/hgfs/Share-CentOS/cmake-2.8.4.tar.gz /usr/cmake-2.8.4.tar.gz
[root@localhost ~]# cd /usr

解壓並安裝cmake
[root@localhost usr]# tar xzvf cmake-2.8.4.tar.gz
[root@localhost usr]# cd cmake-2.8.4
[root@localhost cmake-2.8.4]# ./bootstrap

---------------------------------------------
CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C compiler on this system.
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.

---------------------------------------------
Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
報錯:缺少C的編譯器
解決辦法:安裝gcc編譯器
[root@localhost ~]# yum install gcc

繼續安裝Cmake
[root@localhost cmake-2.8.4]# ./bootstrap

---------------------------------------------
CMake 2.8.4, Copyright 2000-2009 Kitware, Inc.
C compiler on this system is: cc
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
報錯:缺少C++編譯器
解決辦法:安裝gcc-c++編譯器
[root@localhost ~]# yum install gcc-c++

再次安裝
[root@localhost cmake-2.8.4]# ./bootstrap
沒有報錯,編譯安裝
[root@localhost cmake-2.8.4]# gmake
[root@localhost cmake-2.8.4]# gmake install

4.正式開始安裝MySQL
添加MySQL使用者和使用者組
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql

MySQL源碼包從共用資料夾移至/usr並解壓
[root@localhost ~]mv /mnt/hgfs/Share-CentOS/mysql-5.5.22.tar.gz /usr/mysql-5.5.22.tar.gz
[root@localhost usr]# tar xzvf mysql-5.5.22.tar.gz
[root@localhost usr]# cd mysql-5.5.22

 

Cmake運行
[root@localhost mysql-5.5.22]# cmake .

開始編譯安裝
[root@localhost mysql-5.5.22]# make && make install

進入安裝目錄,將程式二進位的所有權改為root,資料目錄的說有權改為mysql使用者,更新授權表
[root@localhost mysql-5.5.22]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql

安全啟動MySQL(預設密碼為空白)
[root@localhost mysql]#./bin/mysqld_safe –-user=mysql&

報錯:
090408 21:19:24 mysqld_safe Logging to '/var/log/mysqld.log'.
090408 21:19:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
090408 21:19:24 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
原因:
開啟/var/log/mysqld.log檔案得到Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)
Can't start server: can't create PID file: No such file or directory
解決方案:
進入/var/run目錄,發現沒有mysqld目錄,建立mysqld目錄,進入該目錄再建立mysqld.pid檔案,修改檔案屬性 chown -R mysql mysqld .從而解決該問題

串連本機MySQL
[root@localhost mysql]#mysql –u root –p
提示輸入password,預設為空白,按Enter即可

中斷連線
mysql>exit;

關閉MySQL
[root@localhost mysql]# ./bin/mysqladmin -u root shutdown –p

報錯:
bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
原因:
進入/var/lib/mysql目錄,發現mysql.sock檔案
解決方案:
建立串連 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 解決該問題

方便調用,為mysql設定一個軟連結
[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

為root賬戶設定密碼
[root@localhost ~]# cd /usr/local/mysql/bin
[root@localhost mysql]# ./bin/mysqladmin -u root –p password root
Enter Password:root

設定選項檔案,將設定檔拷貝到/etc下
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/mysql.cnf

設定開機自啟動
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# chmod +x /etc/init.d/mysql

通過服務來啟動和關閉Mysql
[root@localhost ~]# service mysql start
[root@localhost ~]# service mysql shutdown

報錯:啟動mysql報錯
Starting MySQL…The server quit without updating PID file (/usr/local/mysql/data/CentOS.pid). [失敗]
解決方案:
在 my.cnf 中
#The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
……
下面增加
datadir=/var/lib/mysql
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/lib/mysql/CentOS.pid

  • 1
  • 2
  • 下一頁

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.