Centos 7 下載安裝 mysql server 5.7
更改權限
[zoro@localhost ~]$ su root
輸入密碼進來 管理者命令行
切換目錄
[root@localhost zoro]# cd /root
下載安裝包MySQL5.7 Linux版本
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
打開目錄有這麼個包
[root@localhost ~]# ls
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
安裝依賴
[root@localhost ~]# rpm -qa |grep libaio
[root@localhost ~]#
[root@localhost ~]# yum -y install libaio
// 安裝好後查看
[root@localhost ~]# rpm -qa |grep libaio
libaio-0.3.109-13.el7.x86_64
[root@localhost ~]# rpm -qa | grep numactl
[root@localhost ~]#
[root@localhost ~]# yum -y install numactl
// 安裝好後查看
[root@localhost ~]# rpm -qa | grep numactl
numactl-libs-2.0.9-7.el7.x86_64
準備工作完畢!!!
解壓準備好的安裝包
[root@localhost ~]# tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
名字更改爲mysql 並且修改位置
[root@localhost ~]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
[root@localhost ~]# cd /usr/local
創建mysql組,創建mysql用戶,修改權限
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql
//修改文件用戶
[root@localhost local]# chown -R mysql mysql/
//修改文件用戶組
[root@localhost local]# chgrp -R mysql mysql/
[root@localhost local]# ll
mysql 文件夾下創建data 目錄
[root@localhost local]# mkdir /usr/local/mysql/data
編譯安裝並初始化mysql,務必記住初始化輸出日誌末尾的密碼(數據庫管理員臨時密碼)
cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
2024-04-29T23:56:01.694886Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-04-29T23:56:02.130726Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-04-29T23:56:02.209312Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-04-29T23:56:02.285282Z 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: 08ae1c14-0684-11ef-bab1-5254007da070.
2024-04-29T23:56:02.292959Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-04-29T23:56:02.293617Z 1 [Note] A temporary password is generated for root@localhost: prrh2py 複製密碼
修改配置文件
[root@localhost local]# vi /etc/my.cnf
複製下面的, 貼到 /etc/my.cnf 裏面
[mysql]
# 設置mysql客戶端默認字符集
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
skip-name-resolve
#設置3306端⼝
port = 3306
socket=/var/lib/mysql/mysql.sock
# 設置mysql的安裝⽬錄
basedir=/usr/local/mysql
# 設置mysql數據庫的數據的存放⽬錄
datadir=/usr/local/mysql/data
# 允許最⼤連接數
max_connections=200
# 服務端使⽤的字符集默認爲8⽐特編碼的latin1字符集
character-set-server=utf8
# 創建新表時將使⽤的默認存儲引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
cd /usr/local/mysql
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]#
複製啓動腳本到資源⽬錄
[root@localhost mysql]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900
# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
:wq
:wq 保存退出
設置爲可執行狀態
//授權爲可執行狀態
//⾸先增加 mysqld 服務控制腳本執⾏權限:
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
//開機啓動
//同時將 mysqld 服務加⼊到系統服務:
[root@localhost mysql]# chkconfig --add mysqld
//最後檢查 mysqld 服務是否已經⽣效即可:
[root@localhost mysql]# chkconfig --list mysqld
啓動mysql
[root@localhost mysql]# service mysqld start
Starting MySQL. [ 確定 ]
Starting MySQL.Logging to '/usr/local/mysql/data/VM-0-2-centos.err'.
2024-04-30T00:06:26.217074Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
ERROR! The server quit without updating PID file (/usr/local/mysql/data/VM-0-2-centos.pid).
配置環境變量
[root@localhost ~]# vi /etc/profile
//添加下面一行wq保存退出
export PATH=$PATH:/usr/local/mysql/bin
:wq
[root@localhost ~]#
//
[root@localhost ~]# source /etc/profile
登錄mysql 密碼是初始化中的最後localhost:後面的密碼
(base) [root@VM-0-2-centos bin]# mysql
-bash: mysql: command not found
[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.24
Copyright (c) 2000, 2018, 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>
修改密碼
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 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> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>quit
==============================================================================================
但是還是有問題
windows 上的Navicat是連接不上的
這個問題該怎麼解決呢?
打開遠程訪問權限,修改完退出mysql ,quit 命令
BY 後面是數據庫密碼
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>quit
Bye
防火牆開放mysql使用的3306端口
[root@localhost mysql]# cd /root
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
重啓防火牆
[root@localhost ~]# systemctl restart firewalld.service
[root@localhost ~]#
查看防火牆開放的端口
[root@localhost ~]# firewall-cmd --list-ports
3306/tcp
REF鏈接:
https://blog.csdn.net/Yeniden/article/details/136901092