全新以最小化包安裝了64位的CentOS6.3系統,做爲本地的Web服務器使用,現記錄全過程
第六步,安裝mysql5.5數據庫v5.5.28html
mysql從5.5版本開始,再也不使用./configure編譯,而是使用cmake編譯器,具體的cmake編譯參數能夠參考mysql官網文檔(※ 很是重要)
http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.htmlmysql
mysql-5.5.28.tar.gz源碼包下載地址:
http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28.tar.gzlinux
個人mysql目錄配置以下:
安裝路徑:/usr/local/mysql
數據庫路徑:/data/mysql
源碼包存放位置:/usr/softwarec++
準備工做:安裝基本依賴包,先用yum安裝cmake、automake 、autoconf ,另MySQL 5.5.x須要最少安裝的包有:bison,gcc、gcc-c++、ncurses-devel
[root@localhost ~]# yum install cmake make -y
[root@localhost ~]# yum install gcc gcc-c++ autoconf bison automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* -y
[root@localhost ~]# cp /root/mysql-5.5.28.tar.gz /usr/software/
[root@localhost ~]# cd /usr/software
開始編譯安裝
[root@localhost ~]# tar -zxvf mysql-5.5.28.tar.gz
[root@localhost ~]# cd mysql-5.5.28
[root@localhost ~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql/ \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
[root@localhost ~]# make && make installsql
mysql官網英文文檔簡單翻譯說明一下
The MyISAM, MERGE, MEMORY, and CSV engines are mandatory (always compiled into the server) and need not be installed explicitly.(說明:mysql默認支持的數據庫引擎有MyISAM, MERGE, MEMORY, CSV,無需在編譯時再聲明)
因此上面的編譯條件省掉了以下兩行
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
但INNODB必定要聲明式安裝,因此多了這一行
-DWITH_INNOBASE_STORAGE_ENGINE=1 \數據庫
[root@localhost ~]# groupadd mysql #添加mysql用戶組
[root@localhost ~]# useradd mysql -g mysql -s /sbin/nologin # 添加mysql用戶centos
如下帶紅色字體的命令很是很是,必需要執行
[root@localhost ~]# cd /usr/local/mysql
[root@localhost ~]# chown mysql.mysql -R . #將mysql目錄賦予mysql用戶的執行權限
[root@localhost ~]# chown mysql.mysql -R /data/mysql
[root@localhost ~]# cp support-files/my-medium.cnf /etc/my.cnf #mysql配置文件
[root@localhost ~]# chmod 755 scripts/mysql_install_db #賦予mysql_install_db執行權限服務器
如下命令爲mysql 啓動及自啓動配置
[root@localhost ~]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/
[root@localhost ~]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod 755 /etc/init.d/mysqld
查看mysqld服務是否設置爲開機啓動
[root@localhost ~]# chkconfig --list|grep mysqld
設置爲開機啓動
[root@localhost ~]# chkconfig mysqld onide
啓動mysql數據庫,會輸出一系列有用的信息,告訴你接下去如何初始化mysql
[root@CentOSmysql]# service mysqld start
初始化 MySQL 數據庫: Installing MySQL system tables...
OK
Filling help tables...
OK字體
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h centos.huoba password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
按照上述英文,咱們來初始化管理員root的密碼
[root@localhost ~]# /usr/bin/mysqladmin -u root password 'yourpassword'
衆所周知,mysql有兩種賬號類型,即localhost和%,前者限本機鏈接mysql,後者可用於其它機器遠程鏈接mysql最後,處理賬號登陸問題,讓root賬號密碼能夠本地和遠程鏈接使用[root@localhost ~]# mysql -u root -p #敲入該命令後,屏幕會提示輸入密碼,輸入上一步設置的yourpassword 刪除root密碼爲空的記錄 mysql> use mysql; mysql> delete from user where password=''; mysql> flush privileges; 配置mysql容許root遠程登陸 #登陸 mysql> grant all privileges on *.* to root@'%' identified by "root"; mysql> flush privileges; mysql> select User,Password,Host from user;
上述命令若是執行成功 mysql> quit 至此,mysql安裝已經所有結束。