溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CentOS7服務(wù)器如何安裝MySQL

發(fā)布時間:2022-01-19 15:49:29 來源:億速云 閱讀:153 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要為大家展示了“CentOS7服務(wù)器如何安裝MySQL”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“CentOS7服務(wù)器如何安裝MySQL”這篇文章吧。

  • MySQL的yun源地址:https://dev.mysql.com/downloads/repo/yum/

  • MySQL的yun源地址使用文檔:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

下載mysql的yum源

可以使用ustc的源wget http://centos.ustc.edu.cn/mysql-repo/mysql57-community-release-el7-11.noarch.rpm

wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm             //下載mysql的yum源
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm                                   //安裝yum源
yum repolist all | grep mysql                                                          //查看所有mysql的yum源
yum repolist enabled | grep mysql                                                      //查看啟用的的mysql的yum源
vim /etc/yum.repos.d/mysql-community.repo                                              //修改mysql源

啟用mysql5.6的源,關(guān)閉mysql5.7的源。enabled=1為啟用。

[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

安裝mysql

yum install mysql-community-server
mkdir /data/mysql                         // 創(chuàng)建mysql數(shù)據(jù)存放文件夾
chown mysql:mysql /data/mysql             // 將文件夾的所有者設(shè)置為mysql

修改數(shù)據(jù)庫文件位置,但不要修改sock位置,否則會出現(xiàn)找不到sock的問題。

vim /etc/my.conf

修改端口號

[client]
# 設(shè)置客戶端字符集。在服務(wù)器使用 mysql -umyname -p 登錄時使用的字符集,不設(shè)置會導(dǎo)致顯示亂碼
default-character-set=utf8mb4

[mysqld]
# 服務(wù)器端口號
port=53306
# 服務(wù)器字符集
character-set-server=utf8mb4
# innodb內(nèi)存,對性能影響巨大,如果是專用數(shù)據(jù)庫服務(wù)器,可以設(shè)置為物理內(nèi)存的70%-80%
innodb_buffer_pool_size = 1024M
# 數(shù)據(jù)庫最大連接數(shù)
max_connections=5000
# 設(shè)置在網(wǎng)絡(luò)傳輸中一次消息傳輸量的最大值。系統(tǒng)默認(rèn)值為4MB,最大值是1GB
max_allowed_packet=32M
# innodb日志文件大小,默認(rèn)為48M
innodb_log_file_size=128M
# 數(shù)據(jù)庫文件位置
datadir=/data/mysql

mysql自啟動

systemctl start mysqld
systemctl enable mysqld
mysql_secure_installation

常用操作

systemctl restart mysqld                    // 重啟mysql
mysqladmin -u foo -p password               // 修改密碼

創(chuàng)建用戶

mysql -uroot -p                                                   // 登錄mysql
create user 'jspxcms'@'%' identified by 'mypass';                 // %代表可以在任何地方登錄數(shù)據(jù)庫。刪除用戶:drop user myname
#create user 'jspxcms'@'localhost' identified by 'mypass';         // localhost代表只能在本機登錄數(shù)據(jù)庫
#update user set password=password('mypass') where user='jspxcms';    // 修改密碼
create database jspxcms;                                          // 創(chuàng)建數(shù)據(jù)庫
grant all on jspxcms.* to 'jspxcms'@'%';                          // 賦權(quán)
flush privileges;                                                 // 刷新系統(tǒng)權(quán)限表
show databases;                                                   // 查看數(shù)據(jù)庫
use mysql;                                                        // 切換到mysql數(shù)據(jù)庫
select user,host from user;                                       // 顯示用戶名和可以登錄的主機
show variables like 'character%';                                 // 顯示字符集
show variables like 'collation%';
show variables like '%max_connections%';                          // 顯示最大連接數(shù)
exit;                                                             // 退出

修改密碼

mysqladmin -h 111.222.333.444 -u jspxcms -p password

以上是“CentOS7服務(wù)器如何安裝MySQL”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI