Centos6 配置安裝 mysql5.7

 

1、下載安裝包
http://dev.mysql.com/downloads/mysql/#downloads

Select Operating System:選擇Linux-Generic

Select OS Version:選擇Linux - Generic (glibc 2.12) (x86, 64-bit)

下載Compressed TAR Archive下面的tar.gz包

 

2、 檢查庫文件是否存在,如有刪除。
[root@localhost Desktop]$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64

[root@localhost ~]# rpm -e mysql-libs-5.1.52.x86_64 --nodeps

 

3.檢查mysql組和用戶是否存在,如無創建。
[root@localhost ~]# cat /etc/group | grep mysql
mysql:x:490:
[root@localhost ~]# cat /etc/passwd | grep mysql
mysql:x:496:490::/home/mysql:/bin/bash
以上爲默認存在的情況,如無,執行添加命令:
[root@localhost ~]#groupadd mysql
[root@localhost ~]#useradd -r -g mysql mysql
//useradd -r參數表示mysql用戶是系統用戶,不可用於登錄系統。

 

4.解壓TAR包並重命名(mysql包在/opt/software)、創建mysql的data文件夾

tar -zxvf /opt/software/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local
mv /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64/  /usr/local/mysql
mkdir /usr/local/mysql/data


 5.安裝和初始化數據庫

warnging:部分mysql包support-file目錄下沒有my-default.cnf,可將下面方框內內容複製保存到/usr/localmysql/support-file/my-default.cnf

若support-file目錄下存在my-default.cnf,則修改basedir、datadir部分即可(注意複製完全,查看有無多餘亂碼字符)

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysql]
# 設置mysql客戶端默認字符集
default-character-set=utf8

[mysqld]
#log-bin=mysql-bin

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M


# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin


# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
# server_id = .....
# socket = .....


# 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 


# 服務端使用的字符集默認爲8比特編碼的latin1字符集
character-set-server=utf8


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

 把support-files下的my-default.cnf複製到/etc並重命名,mysql.server複製到/etc/init.d並重命

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

修改mysql目錄的文件擁有者

chown -R mysql:mysql /usr/local/mysql/

執行安裝

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

2016-06-01T20:39:38.335054Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-06-01T20:39:38.335124Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-06-01T20:39:38.335129Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-06-01T20:39:40.439194Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-06-01T20:39:40.718820Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-06-01T20:39:40.781181Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b9263cbc-7cd1-11e9-b630-000c29cad4b5.
2016-06-01T20:39:40.793759Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-06-01T20:39:40.794421Z 1 [Note] A temporary password is generated for root@localhost:
EGYWO4sdT5,t

(記住root登錄的臨時密碼,紅色字體處)

linux下安全打開mysql
 

[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1]2932
[root@localhost bin]# 2016-06-01T22:27:09.708557Z mysqld_safe Logging to'/usr/local/mysql/data/localhost.localdomain.err'.
2016-06-01T22:27:09.854913Z mysqld_safe Starting mysqld daemon with databasesfrom /usr/local/mysql/data(這裏需要回車)

[root@localhost bin]# /etc/init.d/mysqld restart
Shutting downMySQL..2017-11-03T02:55:33.863504Z mysqld_safe mysqld from pid file/usr/local/mysql/data/localhost.localdomain.pid ended

 SUCCESS!

Starting MySQL. SUCCESS!

[1]+ Done                   mysqld_safe --user=mysql

 

[root@localhost bin]# 

 

 

配置環境變量

在/etc/profile 尾部增加export PATH=/usr/local/mysql/bin:$PATH

[root@localhost /]# source /etc/profile

 


//設置開機啓動
 

[root@localhost bin]# chkconfig --level 35 mysqld on

6.初始化密碼

複製上面臨時密碼

//登陸數據庫

[root@localhost bin]# mysql -u root -p
Enter password: 

//修改root賬號密碼

mysql> SET PASSWORD = PASSWORD('root');

mysql> flush privileges;

7.添加遠程訪問權限

mysql> use mysql; 

mysql> update user set host = '%' where user = 'root';

//退出數據庫

mysql>exit;

 

[root@localhost bin]# /etc/init.d/mysqld restart

8、開啓3306端口

[root@localhost bin]# vi /etc/sysconfig/iptables

增加

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

重啓防火牆

[root@localhost bin]# /etc/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
[root@localhost bin]#

 

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