安裝依賴 mysql 5.6.40二進位包下載地址 1.下載MySQL 5.6.40二進位包 2.解壓縮mysql二進位包到/usr/local 3.修改名稱、做軟連接 4.創建mysql用戶和組 //創建mysql組 //創建mysql用戶 5.拷貝主配置文件 //備份/etc/my.cnf // ...
安裝依賴
yum install -y gcc gcc-c++ automake autoconf
yum -y install cmake bison-devel ncurses-devel libaio-devel
mysql-5.6.40二進位包下載地址
https://downloads.mysql.com/archives/get/file/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
1.下載MySQL-5.6.40二進位包
[root@7-test1 ~]# wget https://downloads.mysql.com/archives/get/file/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
2.解壓縮mysql二進位包到/usr/local
[root@7-test1 ~]# tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local
3.修改名稱、做軟連接
[root@7-test1 ~]# cd /usr/local
[root@7-test1 local]# mv mysql-5.6.40-linux-glibc2.12-x86_64 mysql-5.6.40
[root@7-test1 local]# ln -s mysql-5.6.40 mysql
4.創建mysql用戶和組
//創建mysql組
[root@7-test1 local]# groupadd mysql
//創建mysql用戶
[root@7-test1 local]# useradd -g mysql -s /bin/false mysql
5.拷貝主配置文件
//備份/etc/my.cnf
[root@7-test1 local]# mv /etc/my.cnf /etc/my.cnf.old
//拷貝主配置文件
[root@7-test1 ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
6.拷貝啟動腳本
[root@7-test1 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
7.初始化mysql
//進入/usr/local/mysql/scripts
[root@7-test1 ~]# cd /usr/local/mysql/scripts
//初始化前安裝依賴包
[root@test1 scripts]# yum -y install autoconf
//初始化mysql
[root@7-test1 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
--user #指定mysql用戶
--basedir #指定mysql安裝目錄
--datadir #指定mysql數據目錄
初始化報錯
[root@7-test1 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper
原因:缺少autoconf依賴包
解決方法
[root@7-test1 scripts]# yum -y install autoconf
8.添加mysql命令環境變數
//導出mysql命令環境變數
[root@7-test1 scripts]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
//使配置生效
[root@7-test1 scripts]# source /etc/profile
9.配置systemd管理mysql
[root@7-test1 scripts]# vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
10.啟動mysql、檢查啟動
//啟動mysql
[root@7-test1 scripts]# systemctl start mysqld ; systemctl enable mysqld
[root@7-test1 scripts]# netstat -ntpl | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 31349/mysqld
11.進入mysql並設置密碼
//設置mysql密碼
mysql> set password=password('123');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)