Centos7安裝MySQL5.7

1.下載好jar包;鏈接:https://pan.baidu.com/s/1LrKqPt4lMPcPgW4oz7JnoA 
提取碼:yi6m 
沒有配置好靜態IP參考此文章
文檔:centos安裝,mysql .doc
鏈接:http://note.youdao.com/noteshare?id=38b747d0fbcd64c683591419c5bba90d&sub=FF18945C486F400CADDE864134A9C76

2.配置好靜態ip後,我是用的Xshell連接,成功後會出現這樣
在這裏插入圖片描述
3.然後使用rz 命令 把剛纔下載好的jar包上傳到根目錄下
在這裏插入圖片描述
4.然後輸入ls 命令就能看到上傳的jar 包,注意藍色標註的地方,剛開始上傳是沒有的,是解壓過後的,
輸入以下命令創建 文件待會解壓是要用 mkdir /usr/local
在這裏插入圖片描述

[root@localhost ~]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
實際生產環境:
[root@localhost ~]# mv /usr/local/mysql-5.7.26-linux-glibc2.12-x86_64/ /usr/local/mysql
新增mysql用戶組:
[root@localhost ~]# groupadd mysql
新增用戶
[root@localhost ~]# useradd -r -g mysql mysql
給mysql 目錄權限
[root@localhost ~]# cd /usr/local/
[root@localhost local]# 	到初始化環境的目錄
[root@localhost mysql]# mkdir log
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown -R mysql:mysql ../mysql
初始化數據和指定安裝目錄和數據目錄
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-04-19T03:23:25.059135Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-19T03:23:25.422900Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-19T03:23:25.476253Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-19T03:23:25.578366Z 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: 7e3573fb-6252-11e9-b2e0-000c2950fbf4.
2019-04-19T03:23:25.581778Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-19T03:23:25.584681Z 1 [Note] A temporary password is generated for root@localhost: We.#yr1?zbYS  (找一個地方保存這個,隨機生成的mysql數據庫密碼)
複製啓動文件
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# chmod +x /etc/init.d/mysqld
.修改啓動路徑
[root@localhost support-files]# vi /etc/init.d/mysqld 
     46 basedir=/usr/local/mysql
     47 datadir=/usr/local/mysql/data
增加環境變量 (最下面添加)
[root@localhost support-files]# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost support-files]# source /etc/profile
修改配置文件,輸入以下命令是有可能什麼都沒有,如果沒有,把下面這段內容輔助到該文件裏面,如果有,請修改與之不同的地方
[root@localhost support-files]# vi /etc/my.cnf
[client]
port=3306
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#socket=/usr/local/mysql/mysql.sock
socket=/tmp/mysql.sock
user=mysql
#skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
#
# include all files from the config directory
#
#includedir /etc/my.cnf.d
添加開啓自啓
[root@localhost support-files]# chkconfig --add mysqld
[root@localhost support-files]# chkconfig mysqld on
啓動
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.2019-04-19T03:30:21.872260Z mysqld_safe error: log-error set to '/usr/local/mysql/log/mysqld.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
[root@localhost log]# touch mysqld.log
[root@localhost log]# chmod -R 777 /usr/local/mysql
[root@localhost data]# touch localhost.localdomain.pid
[root@localhost data]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
[root@localhost data]# lsof -i:3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  49214 mysql   18u  IPv6  93463      0t0  TCP *:mysql (LISTEN)
修改密碼:
[root@localhost ~]# mysql -uroot -p7yT*Q?.rs>H7
mysql>  set password=password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章