前言
有朋友問怎麼編譯安裝mysql5.7版本,所以趁今天分享下之前在ubuntu14.04系統編譯安裝的過程,希望對大家有點幫助。
環境:
服務器關閉防火牆,外部訪問mysql,或者開通3306端口
root@ubuntu:~# ufw disable
Firewall stopped and disabled on system startup
1、創建服務啟動用戶,解壓並移動到安裝位置
安裝包地址:/opt/mysql/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
1.1 解壓安裝mysql
#tar -xvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz -C /usr/local
root@ubuntu:/usr/local/mysql# ll
total 60
drwxr-xr-x 9 root root 4096 Nov 8 22:53 ./
drwxr-xr-x 16 root root 4096 Nov 8 22:48 ../
drwxr-xr-x 2 root root 4096 Nov 8 22:51 bin/
-rw-r--r-- 1 7161 31415 17987 Sep 28 2016 COPYING
drwxr-xr-x 2 root root 4096 Nov 8 22:52 docs/
drwxr-xr-x 3 root root 4096 Nov 8 22:50 include/
drwxr-xr-x 5 root root 4096 Nov 8 22:52 lib/
drwxr-xr-x 4 root root 4096 Nov 8 22:51 man/
-rw-r--r-- 1 7161 31415 2478 Sep 28 2016 README
drwxr-xr-x 28 root root 4096 Nov 8 22:52 share/
drwxr-xr-x 2 root root 4096 Nov 8 22:52 support-files/
root@ubuntu:/usr/local/mysql# pwd
/usr/local/mysql
1.2 創建服務啟動用戶
#groupadd mysql
#useradd -r -g mysql -s /bin/bash mysql -d /home/mysql -m
1.3 設置文件權限
#chown -R mysql:mysql /usr/local/mysql
2.mysql文件相關配置
2.1 設置mysql服務啟動腳本
2.1.1 添加mysql為系統服務
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#chmod 755 /etc/init.d/mysqld
配置後可通過service mysqld start 啟動mysql服務
2.2 修改mysql配置文件my.cnf
#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
(查看support-files目錄下是否有mysql-medium.cnf文件,有的話直接複製)
#vi /etc/my.cnf
[mysqld]
#socket = /usr/local/mysql/data/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
max_allowed_packet=50M
lower_case_table_names=0
character_set_server = utf8
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
2.3 添加mysql為系統變量
#vi /etc/profile ==>添加PATH=$PATH:MYSQL安裝包路徑/bin
export PATH=$PATH:/usr/local/mysql/bin
#source /etc/profile //使文件生效
#echo $PATH //查看是否加入成功
root@ubuntu:/usr/local/mysql# echo $PATH
/usr/local/jdk1.8.0_131/bin:/home/zookeeper-3.4.9//bin:/usr/local/jdk1.8.0_131/bin:/home/zookeeper-3.4.9//bin:/usr/local/sbin:/usr/lo
cal/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/mysql/bin
3.mysql數據庫配置
3.1 安裝mysql數據庫(mysql用戶)
初始化生成基礎庫(需把之前的/data文件刪除)
#./bin/mysqld --initialize
mysql@ubuntu:/usr/local/mysql$ ./bin/mysqld --initialize
2017-11-09T07:38:38.745575Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-11-09T07:38:38.745823Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-11-09T07:38:38.746638Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_times
tamp server option (see documentation for more details).2017-11-09T07:38:38.746665Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used w
ith strict mode. They will be merged with strict mode in a future release.2017-11-09T07:38:38.746672Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2017-11-09T07:38:40.095496Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-09T07:38:40.573958Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-09T07:38:40.815986Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server ha
s been started. Generating a new UUID: 0184c08c-c521-11e7-84c6-000c291e3617.2017-11-09T07:38:40.840897Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-11-09T07:38:40.884876Z 1 [Note] A temporary password is generated for root@localhost: k%T3TJt7&(gm
其中k%T3TJt7&(gm 為mysql初始密碼
/usr/local/mysql/data存放數據庫文件
# chown -R mysql:mysql /usr/local/mysql/data/
4、mysql數據庫相關設置
4.1 啟動mysql數據庫
4.1.1 啟動服務
#service mysqld start
[root@localhost etc]# service mysqld start
Starting MySQL. [確定]
4.1.2 連接MYSQL
#mysql -u root -p
root@ubuntu:/usr/local/mysql/bin# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.16
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.14 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
4.2 設置mysql連接權限
查詢mysql連接用戶情況:
select host,user from user;
設置遠程:
UPDATE user SET Host='%' WHERE User='root' AND Host='localhost'
設置本地連接權限
UPDATE user SET Host='localhost' WHERE User='root' AND Host='127.0.0.1'
grant all privileges on *.* to root@'%' identified by '123456' with grant option;
後面會更多專注分享DBA方面的內容,感興趣的朋友可以關注下!!
閱讀更多 智能運維小講堂 的文章