linux下安裝mysql-5.7.20



 

1、下載地址

  https://downloads.mysql.com/archives/community/ 

  

 

 

 

 

 

 

 

 

 

 

 

 

2、安裝步驟

解壓: 

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf /path/to/mysql-VERSION-OS.tar.gz
mv full-path-to-mysql-VERSION-OS mysql
chown -R mysql mysql/
chgrp -R mysql mysql/
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files

創建配置文件:

#先安裝一下這個,要不然初始化有可能會報錯
yum install libaio

 my.cnf配置:

#創建配置文件,內容如下,可以添加你需要的配置:
vim /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [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 # # 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 port=3309 datadir=/data/mysql socket=/data/mysql/mysql.sock skip-name-resolve #skip-grant-tables max_connections=1000 character_set_server = utf8 wait_timeout=31536000 interactive_timeout=31536000 collation-server=utf8_general_ci lower_case_table_names=1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/data/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [client] socket=/data/mysql/mysql.sock default-character-set = utf8 [mysql] default-character-set = utf8 [mysql.server] default-character-set = utf8 [mysqld_safe] default-character-set = utf8 #保存內容,按esc輸入如下命令 :wq

 初始化數據庫:

mkdir /data/log
chown -R mysql:mysql /data
cd /var/run/
mkdir mysqld
chmod 777 mysqld
cd mysqld
vim mysqld.pid

chmod 777 mysqld.pid
chown mysql:mysql mysqld.pid

/usr/local/mysql/bin/mysqld --initialize --user=mysql

查看初始密碼:

cat /data/log/mysqld.log
#執行后關注最后一點:root@localhost: 這里就是初始密碼

啟動服務,進入mysql,修改初始密碼,運行遠程連接(這里執行完后,密碼將變成:123456)

/usr/local/mysql/support-files/mysql.server start

#vim /etc/mysql/my.cnf
#在[mysqld]項下添加
#skip-grant-tables
#service mysqld restart
cd /usr/local/mysql/bin
./mysql -uroot -p
執行后輸入初始密碼
alter user 'root'@'localhost' identified by '123456'; 
flush privileges;
use mysql;

#設置遠程登錄
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;

開機自啟:

cd /usr/local/mysql/
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
8、使用service mysqld命令啟動/停止服務
service mysqld start/stop/restart

防火牆開開放3309端口:

vim /etc/sysconfig/iptables
service iptables restart
service mysqld restart

配置全局環境變量:

vi /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
設置環境變量立即生效
# source /etc/profile

查看安裝路徑:

find / -name mysql

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM