操做系統版本:redhat 6.7 64位mysql
[root@mysql ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
linux
數據庫版本:MySQL5.7sql
下載地址:https://downloads.mysql.com/archives/community/數據庫
我下載的包爲:mysql-5.7.24-linux-glibc2.12-x86_64.tar.gzbootstrap
(一)安裝前的準備vim
(1)查看服務器上是否已經安裝了MySQL。RedHat Linux系統安裝時,若是選擇了MySQL數據庫,那麼服務器上會存在MySQL數據庫,須要先卸載。bash
# 查看是否存在mysql安裝包 [root@mysql etc]# rpm -qa| grep mysql mysql-community-common-5.7.21-1.el7.x86_64 # 若是存在,須要先卸載 [root@mysql etc]# rpm -e mysql-community-common-5.7.21-1.el7.x86_64
(2)查看服務器上是否存在mariadb數據庫。mariadb是MySQL的一個分支,須要卸載服務器
[root@mysql mysql]# rpm -qa |grep mariadb
(3) 刪除/etc/my.cnf文件。該文件相似Oracle的參數文件ide
[root@mysql mysql]# rm /etc/my.cnf rm: cannot remove `/etc/my.cnf': No such file or directory
(4)建立mysql用戶來管理數據庫編碼
[root@mysql mysql]# cat /etc/passwd|grep mysql mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash [root@mysql mysql]# cat /etc/group |grep mysql mysql:x:27:
[root@mysql mysql]# groupadd mysql
[root@mysql mysql]# useradd -g mysql mysql
修改mysql用戶密碼:
[root@mysql mysql]# passwd mysql Changing password for user mysql. New password: BAD PASSWORD: it is too short BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully.
(二)安裝MySQL數據庫
mysql安裝路徑:/usr/local/mysql/
數據存放位置::/usr/local/mysql/data
(1)解壓MySQL安裝包
[root@mysql mysql]# tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
(2)將解壓後的文件拷貝到安裝路徑下
[root@mysql mysql]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql/
(3)修改文件的權限
[root@mysql mysql]# cd /usr/local/ [root@mysql local]# ls bin etc games include lib lib64 libexec mysql sbin share src [root@mysql local]# chown -R mysql mysql/ [root@mysql local]# chgrp -R mysql mysql/
(4)建立存放data的文件夾
[root@mysql mysql]# mkdir data [root@mysql mysql]# chown -R mysql:mysql data
(5)在/etc下建立mysql的參數文件my.cnf
[root@mysql etc]# vim my.cnf
[mysql] # 設置mysql客戶端默認字符集 default-character-set=utf8 [mysqld] skip-name-resolve # 設置3306端口 port = 3306 # 設置mysql的安裝目錄 basedir=/usr/local/mysql # 設置mysql數據庫的數據的存放目錄 datadir=/usr/local/mysql/data # 容許最大鏈接數 max_connections=200 # 服務端使用的字符集默認爲8比特編碼的latin1字符集 character-set-server=utf8 # 建立新表時將使用的默認存儲引擎 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M
(6)安裝數據庫
[root@mysql bin]# pwd /usr/local/mysql/bin [root@mysql bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data 2019-04-20 22:17:08 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2019-04-20 22:17:14 [WARNING] The bootstrap log isn't empty: 2019-04-20 22:17:14 [WARNING] 2019-04-20T14:17:08.662276Z 0 [Warning] --bootstrap is deprecated. Please consider using 2019-04-20T14:17:08.663008Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 2019-04-20T14:17:08.663018Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)
(6)設置啓動項
[root@mysql mysql]# ls bin COPYING data docs include lib man README share support-files [root@mysql mysql]# cd ./support-files/mysql mysqld_multi.server mysql-log-rotate mysql.server [root@mysql mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld [root@mysql mysql]# chown 777 /etc/my.cnf [root@mysql mysql]# chmod a+x /etc/init.d/mysqld
(7)開啓數據庫
[root@mysql mysql]# /etc/init.d/mysqld start
Starting MySQL. [ OK ]
查看數據庫狀態
[root@mysql mysql]# service mysqld status MySQL running (39674) [ OK ] # 或者 [root@mysql mysql]# ps -ef|grep mysql mysql 39674 1 0 22:53 pts/0 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=mysql.err --pid-file=/usr/local/mysql/data/mysql.pid --port=3306 root 40719 3339 0 23:13 pts/0 00:00:00 grep mysql
(8)修改數據庫的初始root密碼
(8.1)查看初始密碼
[root@mysql mysql]# cat /root/.mysql_secret # Password set for user 'root@localhost' at 2019-04-20 22:17:08 bkro9k_?=jrM
(8.2)使用初始密碼登陸數據庫,修改初始密碼爲123456
[root@mysql mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.24 mysql> set password=password('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
安裝完成。