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包


(注意:黃底爲用戶輸入,綠底爲shell輸出

 

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包並重命名、創建data文件夾
[root@localhost /]# cd /opt/software/

[root@localhost software]# tar -zxvfmysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local

[root@localhostsoftware]# cd /usr/local/

[root@localhostlocal]# ls

bin  games   lib    libexec                              sbin   src

etc  include lib64 mysql-5.7.19-linux-glibc2.12-x86_64 share

[root@localhostlocal]# mv mysql-5.7.19-linux-glibc2.12-x86_64/ mysql

[root@localhostlocal]# cd mysql/

[root@localhostmysql]# mkdir data

 

 5.安裝和初始化數據庫
[root@localhost mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

2016-06-01 15:23:25 [WARNING] mysql_install_dbis deprecated. Please consider switching to mysqld –initialize

 

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

若support-file目錄下存在my-default.cnf,則修改紅色字體部分即可

# 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.


[mysqld]


# 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 


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 


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

[root@localhost mysql]# cp -a./support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld

 

 

[root@localhost 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
[root@localhost bin]#

 

6.初始化密碼

mysql5.7會生成一個初始化密碼
[root@localhost bin]# cat /root/.mysql_secret 
# Password set for user 'root@localhost' at 2016-06-01 15:23:25 
,xxxxxR5H9

複製該密碼

//登陸數據庫

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

//修改root賬號密碼

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

mysql> flush privileges;

7.添加遠程訪問權限

mysql> use mysql; 

mysql> updateuser 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]#


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