騰訊雲centos7.2安裝MySQL5.5

1、CentOs7版本默認情況下安裝了mariadb-libs,必須先卸載纔可以繼續安裝MySql 
卸載原有MySQL或者Mariadb
1.1查找以前是否安裝mariadb-libs
[root@VM_171_153_centos ~]# rpm -qa | grep -i mariadb-libs
mariadb-libs-5.5.52-1.el7.x86_64
1.2卸載已經安裝的mariadb-libs
[root@VM_171_153_centos ~]# yum remove mariadb-libs-5.5.52-1.el7.x86_64
2.查找是否以前安裝過MySQL
[root@VM_171_153_centos ~]# rpm -qa | grep -i mysql
如果顯示有數據顯示 說明已經安裝了 MySQL 程序
2.1關閉服務
[root@VM_171_153_centos ~]# service mysql stop
或者
[root@VM_171_153_centos ~]# ps -A | grep mysql
[root@VM_171_153_centos ~]# kill -9 進程號
2.2 刪除之前安裝的mysql
[root@VM_171_153_centos ~]# rpm -ve  文件名稱   例如:MySQL-server-5.6.24-1.linux_glibc2.5.x86_64
2.3查找之前老版本mysql的目錄、並且刪除老版本mysql的文件和庫 
[root@VM_171_153_centos ~]# find / -name mysql
查找結果目錄如下,不一樣沒關係,刪掉即可
/var/lib/mysql   
/usr/lib64/mysql   
/usr/local/mysql   
/usr/local/mysql/data/mysql
刪除對應的目錄  
[root@VM_171_153_centos ~]# rm -rf /var/lib/mysql  
[root@VM_171_153_centos ~]# rm -rf /usr/lib64/mysql  
[root@VM_171_153_centos ~]# rm -rf /usr/local/mysql   
刪除配置文檔  
[root@VM_171_153_centos ~]# rm -rf /etc/my.cnf  
2.4再次查找機器是否安裝mysql
[root@VM_171_153_centos ~]# rpm -qa | grep -i mysql
無結果即爲清理乾淨
3正式開始安裝MySQL
3.1下載MySQL  下載地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads
3.2 下載cmake  cmake下載地址:http://www.cmake.org/
4將下載好的文件通過xshell上傳到服務器
4.1安裝rz工具
[root@VM_171_153_centos ~]# yum install lrzsz
4.2上傳文件
[root@VM_171_153_centos ~]# rz
4.3上傳完成
[root@VM_171_153_centos ~]# ls
anaconda-ks.cfg  cmake-2.8.8.tar.gz  mysql-5.5.32.tar.gz
5安裝cmake
5.1解壓cmake
[root@VM_171_153_centos ~]# tar xvzf cmake-2.8.8.tar.gz 
5.2進入cmake
[root@VM_171_153_centos ~]# cd cmake-2.8.8/
5.3安裝cmake
[root@VM_171_153_centos cmake-2.8.8]# ./configure 
報錯
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.
沒有安裝gcc的包
安裝關於c的包
[root@VM_171_153_centos cmake-2.8.8]# yum install gcc
[root@VM_171_153_centos cmake-2.8.8]# yum install gcc-c++
再次執行
[root@VM_171_153_centos cmake-2.8.8]# ./configure
-- Build files have been written to: /root/cmake-2.8.8
---------------------------------------------
CMake has bootstrapped.  Now run gmake.
執行成功
5.4進行make
[root@VM_171_153_centos cmake-2.8.8]# make
[100%] Building CXX object Tests/FindPackageModeMakefileTest/CMakeFiles/foo.dir/foo.cpp.o
Linking CXX static library libfoo.a
[100%] Built target foo
[root@VM_171_153_centos cmake-2.8.8]# make install
6開始安裝MySQL
cd 回到MySQL目錄
6.1解壓mysql
[root@VM_171_153_centos ~]# tar xzvf mysql-5.5.32.tar.gz 
6.2進入目錄
[root@VM_171_153_centos ~]# cd mysql-5.5.32/
6.3進行cmake
[root@VM_171_153_centos mysql-5.5.32]# cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql56 
-DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc/my.cnf  
-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock 
-DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 
-DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
報錯:
CMake Error at cmake/readline.cmake:83 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev,
	  on Redhat and derivates it is ncurses-devel.
centos位rehat版本
少ncurses-devel
安裝ncurses-devel
[root@VM_171_153_centos mysql-5.5.32]# yum install ncurses-devel
6.4刪除cmake配置文件
[root@VM_171_153_centos mysql-5.5.32]# rm -f CMakeCache.txt 
再次cmake
執行6.3
cmake 解釋
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql56  \    #安裝路徑   
 -DMYSQL_DATADIR=/usr/local/mysql/data      \    #數據文件存放位置  
 -DSYSCONFDIR=/etc                         \    #my.cnf路徑  
 -DWITH_MYISAM_STORAGE_ENGINE=1            \    #支持MyIASM引擎  
 -DWITH_INNOBASE_STORAGE_ENGINE=1          \    #支持InnoDB引擎  
 -DWITH_MEMORY_STORAGE_ENGINE=1            \    #支持Memory引擎  
 -DWITH_READLINE=1                         \    #快捷鍵功能(我沒用過)  
 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock        \    #連接數據庫socket路徑  
 -DMYSQL_TCP_PORT=3306                     \    #端口    
 -DENABLED_LOCAL_INFILE=1                  \    #允許從本地導入數據  
 -DWITH_PARTITION_STORAGE_ENGINE=1         \    #安裝支持數據庫分區  
 -DEXTRA_CHARSETS=all                      \    #安裝所有的字符集 
 -DDEFAULT_CHARSET=utf8                    \    #默認字符  
 -DDEFAULT_COLLATION=utf8_general_ci  
build完成
-- Build files have been written to: /root/mysql-5.5.32
6.5 make make install
[root@VM_171_153_centos mysql-5.5.32]# make && make install
安裝成功了
7開始配置mysql
7.1 檢查是否有MySQL用戶
[root@VM_171_153_centos mysql-5.5.32]# cat /etc/passwd | grep mysql
[root@VM_171_153_centos mysql-5.5.32]# cat /etc/group | grep mysql
7.2 創建mysql用戶
[root@VM_171_153_centos mysql-5.5.32]# groupadd mysql
[root@VM_171_153_centos mysql-5.5.32]# useradd -g mysql mysql
7.3修改權限
[root@VM_171_153_centos mysql-5.5.32]# chown -R mysql:mysql /usr/local/mysql56
最後 有的位MySQL 我的版本位MySQL56 具體情況 cd /usr/local/  ls查看
7.4繼續下面的操作
[root@VM_171_153_centos mysql-5.5.32]# cd /usr/local/mysql56/
[root@VM_171_153_centos mysql56]# chown -R mysql:mysql .  #這裏最後是有個.的
[root@VM_171_153_centos mysql56]# scripts/mysql_install_db --user=mysql
出錯不要管直接下一部 不影響使用
[root@VM_171_153_centos mysql56]# chown -R root:mysql .
(將權限設置給root用戶,並設置給mysql組, 取消其他用戶的讀寫執行權限,僅留給mysql "rx"讀執行權限,其他用戶無任何權限)  
[root@VM_171_153_centos mysql56]# chown -R mysql:mysql ./data
(數據庫存放目錄設置成mysql用戶mysql組) 
[root@VM_171_153_centos mysql56]# chmod -R ug+rwx  .
(賦予讀寫執行權限,其他用戶權限一律刪除僅給mysql用戶權限)
8開始配置MySQL文件
8.1將mysql的配置文件拷貝到/etc
[root@VM_171_153_centos mysql56]# cd support-files/
[root@VM_171_153_centos support-files]# cp my-medium.cnf /etc/my.cnf
如果你使用mysql5.6 使用下列操作
cp support-files/my-default.cnf  /etc/my.cnf
8.2 修改my.cnf
[root@VM_171_153_centos support-files]# vi /etc/my.cnf 
user=mysql
datadir=/usr/local/mysql56/data
default-storage-engine=MyISAM
在第二個MySQL56有的版本位mysql具體看自己目錄即可
8.3 將啓動文件加載到系統中
[root@VM_171_153_centos support-files]# cp mysql.server /etc/init.d/mysql
現在可以使用下面的命令啓動mysql   
  
# service mysql start   
  
停止mysql服務   
  
# service mysql stop   
  
重啓mysql服務   
  
# service mysql restart  
9修改用戶root密碼
[root@VM_171_153_centos support-files]# chkconfig --add mysql
修改默認root賬戶密碼,默認密碼爲空  
  
修改密碼 cd 切換到mysql所在目錄
[root@VM_171_153_centos support-files]# cd /usr/local/mysql56
有的版本位MySQL  本版本位mysql56
[root@VM_171_153_centos mysql56]# ./bin/mysqladmin -u root password
回車按照提示 輸入密碼
9.1重啓服務器
[root@VM_171_153_centos mysql56]# service mysql restart
即將大功告成
10.將開啓mysql加載到環境變量當中
10.1修改環境變量文件
[root@VM_171_153_centos mysql56]# vi /etc/profile
在文件最後加上
PATH=$PATH:/usr/local/mysql56/bin
export PATH
有的版本目錄位mysql 本版本位mysql56
:wq
保存
10.2執行
[root@VM_171_153_centos mysql56]# source /etc/profile
10.3 輸入mysql -uroot -p密碼
進入成功MySQL至此安裝完成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章