搭建Web服務器之Step8:CentOS6.3安裝MySQL5.5

1.到chinaunix下載MySQL
下載地址:http://download.chinaunix.net/download/0008000/7159.shtml
我下載的版本:mysql-5.5.22.tar.gz html

2.安裝以前先卸載CentOS自帶的MySQL
[root@localhost ~]# yum remove mysql mysql

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

從共享目錄移至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.sql

---------------------------------------------
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
bootstrap

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.22app

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

開始編譯安裝
[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=mysqlui

安全啓動MySQL(默認密碼爲空)
[root@localhost mysql]#./bin/mysqld_safe –-user=mysql&this

報錯:
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

5.安裝設置完畢,以後使用只需啓動-鏈接-斷開-關閉,命令以下:
[root@CentOS mysql]# service mysql start
Starting MySQL..                                           [肯定]
[root@CentOS mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.22 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.07 sec)

mysql> exit;
Bye
[root@CentOS mysql]# service mysql stop
Shutting down MySQL.                                       [肯定]

6.其它: 查看進程命令 ps –ef|grep mysqld kill進程命令 kill –9 進程號

相關文章
相關標籤/搜索