CentOS安裝MySQL(解壓包方式)

一、官網下載Linux通用的MySQL壓縮包

二、上傳解壓

    上傳到Linux服務器,並解壓,我這裏解壓到/usr/local/mysql目錄下

三、添加系統mysql組和用戶mysql

# 添加系統組
groupadd mysql
# 添加用戶
useradd -r -g mysql -s /bin/false mysql

四、開始安裝

  1. 進入mysql目錄
cd /usr/local/mysql

   

目錄 目錄內容
bin mysqld服務器,客戶端和實用程序
docs 信息格式的MySQL手冊
man 手冊頁
include 包含(標題)文件
lib lib庫
share 用於數據庫安裝的錯誤消息,字典和SQL
support-files 其它支持文件

    2、修改當前目錄(mysql)擁有者爲mysql用戶

chown -R mysql:mysql ./

     3、配置my.cnf文件

# 修改前內容
vi /etc/my.cnf
#-----------------------------------------------------------------------#
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# 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=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

# 修改後內容
vi /etc/my.cnf
#---------------------------------------------------------------------#
[client]
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock
# 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/mysql-log/error.log
pid-file=/usr/local/mysql/data/mysql.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

    4、創建日誌文件,創建前需要先創建目錄

# 創建目錄
mkdir /usr/local/mysql/mysql-log
# 創建文件,編輯後直接保存空文件就行
vi /usr/local/mysql/mysql-log/error.log

# 授權
chown mysql:mysql /usr/local/mysql/mysql-log/error.log

    5、初始化

bin/mysqld --initialize --user=mysql

# 如果出現下面報錯
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
# 需要安裝 libaio 依賴庫

    6、支持安全連接

bin/mysql_ssl_rsa_setup

五、添加開機啓動服務和mysql服務

# 添加mysql服務
cp support-files/mysql.server /etc/init.d/mysql
# 添加開機啓動服務
chkconfig --add mysql

# 啓動服務
service mysql start
# 關閉服務
service mysql stop

六、配置系統環境

vi /etc/profile
# 在最下面添加
export MYSQL_HOME=/usr/loca/mysql
export PATH=$MYSQL_HOME/bin:$PATH

# 保存後立即生效
source /etc/profile

七、修改root密碼

# 登錄,密碼就是上面初始化的時候生成的
mysql -u root -p
# 修改密碼
alter user 'root'@'localhost' identified by 'newpassword';
# 刷新權限
flush privileges;
--------------------------------------------------------------------


# 新增用戶
create user 'test'@'%' identified by '123456';
# 給用戶授權
grant all privileges on *.* to test@'%' with grant option;

# 如果使用navicat連接,加密方式不同,有時候需要使用navicat的加密方式
alter user 'test'@'%' identified with mysql_native_password by '123456';

八、原文連接

https://www.cnblogs.com/h--d/p/9556758.html

 

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