1. 程式人生 > >centos6.5下編譯安裝單例項MySQL5.1

centos6.5下編譯安裝單例項MySQL5.1

MySQL5.1版本安裝3步曲:

1)         ./configure

2)         make

3)         make install

檢視系統版本號

[[email protected] ~]# cat /etc/redhat-release

[[email protected] ~]# uname -m

[[email protected]

~]# uname -r

解壓MySQL包

[[email protected] tools]# tar xf mysql-5.1.72.tar.gz

建立MySQL賬戶

[[email protected] tools]# groupadd -g 49 mysql

[[email protected] tools]# useradd mysql -u 49 -g 49 -M -s /sbin/nologin

[[email protected] tools]# id mysql

uid=49(mysql) gid=49(mysql) groups=49(mysql)

安裝依賴包

[[email protected] mysql-5.1.72]# yum install ncurses-devel -y

編譯安裝MySQL5.1

[[email protected] tools]# cd mysql-5.1.72

[[email protected] tools]# ./configure \

--prefix=/application/mysql5.1.72 \

--with-unix-socket-path=/application/mysql5.1.72/tmp/mysql.sock \

--localstatedir=/application/mysql5.1.72/data \

--enable-assembler \

--enable-thread-safe-client \

--with-mysql-user=mysql \

--with-big-tables \

--without-debug \

--with-pthread \

--enable-assembler \

--with-extra-charsets=complex \

--with-readline \

--with-ssl \

--with-embedded-server \

--enable-local-infile \

--with-plugins=partition,innobase \

--with-mysqld-ldflags=-all-static \

--with-client-ldflags=-all-static 

[[email protected] mysql-5.1.72]# echo $?

0

[[email protected] mysql-5.1.72]# make && make install

建立軟連結和新增hosts解析

[[email protected] mysql-5.1.72]# ln -s /application/mysql5.1.72/ /application/mysql

[[email protected] mysql-5.1.72]# ll /application/mysql

lrwxrwxrwx 1 root root 25 Oct 23 13:15 /application/mysql -> /application/mysql5.1.72/

[[email protected] support-files]# vi /etc/hosts          #新增本機主機名至hosts中

建立存放MySQL資料庫的目錄並授權

[[email protected] support-files]# mkdir /application/mysql/data -p            #授權MySQL管理目錄許可權

[[email protected] support-files]# chown -R mysql.mysql /application/mysql/       #建立MySQL初始化的檔案

[[email protected] support-files]# chmod 1777 /tmp

初始化MySQL資料庫

[[email protected] support-files]# \cp my-small.cnf /etc/my.cnf     #實驗環境選擇小的配置檔案

[[email protected] support-files]# /application/mysql/bin/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql  

新增PATH環境變數

[[email protected] support-files]# echo "PATH="/application/mysql/bin:$PATH"" >>/etc/profile

[[email protected] support-files]# tail -1 /etc/profile

PATH=/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[[email protected] support-files]# \. /etc/profile           #立刻生效

新增MySQL至開機自啟動

[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld  #直接拷貝到/etc/init.d/

[[email protected] support-files]# chmod +x /etc/init.d/mysqld 

[[email protected] support-files]# chkconfig --add mysqld               #新增到chkconfig開機自啟動

[[email protected] support-files]# chkconfig --level 3 mysqld on            #開機自啟動

[[email protected] support-files]# /etc/init.d/mysqld                      #如果此步沒有出現以下引數,就要先授權x許可權

Usage: /etc/init.d/mysqld  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]

[[email protected] support-files]# /etc/init.d/mysqld start                                           #啟動MySQL服務

[[email protected] support-files]# lsof -i :3306

MySQL資料庫2種啟動方式

第一種:

[[email protected] support-files]# /etc/init.d/mysqld start                       #啟動MySQL服務

第二種:

[[email protected] support-files]# /application/mysql/bin/mysqld_safe &        #啟動MySQL服務

注意:最好不要混合使用,混合使用有可能報錯,雖然本質上是一樣的啟動方法

[[email protected] mysql-5.1.72]# ps -ef|grep mysqld  #檢視啟動相關資訊

root      1035     1  0 17:47 pts/0    00:00:00 /bin/sh /application/mysql5.1.72/bin/mysqld_safe --datadir=/application/mysql5.1.72/data --pid-file=/application/mysql5.1.72/data/meinv01.pid

mysql     1147  1035  0 17:47 pts/0    00:00:00 /application/mysql5.1.72/libexec/mysqld --basedir=/application/mysql5.1.72 --datadir=/application/mysql5.1.72/data --user=mysql --log-error=/application/mysql5.1.72/data/meinv01.err --pid-file=/application/mysql5.1.72/data/meinv01.pid --socket=/application/mysql5.1.72/tmp/mysql.sock --port=3306

root      1169   951  0 17:52 pts/0    00:00:00 grep --color=auto mysqld

修改MySQL登入密碼

/application/mysql/bin/mysqladmin -u root password 'new-password'       #設定密碼的方法