【教程】Linux下MySQL 8.0安装配置
1、編譯安裝MySQL8.0
版本信息
#cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
安裝依賴包
yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel
rpm -qa |grep libaio
yum install libaio libaio-devel
下載源碼包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gz
創建用戶和建立數據目錄并賦予用戶目錄權限
groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
mkdir -p /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql
chmod -R 755 /usr/local/mysql/
chmod -R 755 /data/mysql/
解壓并開始安裝
tar -zxf mysql-boost-8.0.12.tar.gz
配置
cd mysql-8.0.12
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql
-DSYSCONFDIR=/etc
-DMYSQL_TCP_PORT=3306
-DWITH_BOOST=~/mysql-8.0.12/boost
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DENABLED_LOCAL_INFILE=ON
-DWITH_INNODB_MEMCACHED=ON
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
配置參數說明:
CMAKE_INSTALL_PREFIX :指定基礎安裝目錄
MYSQL_DATADIR :指定數據目錄
SYSCONFDIR=/etc :指定配置文件掃描目錄
MYSQL_TCP_PORT :指定端口號
WITH_BOOST :指定boost所在目錄
DEFAULT_CHARSET :指定默認字符集
DEFAULT_COLLATION :指定默認排序規則
ENABLED_LOCAL_INFILE=ON :是否為load data infile啟用local
WITH_INNODB_MEMCACHED=ON :是否生成memcached共享庫
編譯&安裝
make && make install
初始化數據庫
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
建立配置文件
cat > /etc/my.cnf <<EOF
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
#user=root
#password=123
[mysqld]
server-id=1
#skip-grant-tables
port=3306
user=mysql
max_connections=200
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
pid-file=/data/mysql/mysql.pid
init-connect=‘SET NAMES utf8’
character-set-server=utf8
default-storage-engine=INNODB
log_error=/data/mysql/mysql-error.log
slow_query_log_file=/data/mysql/mysql-slow.log
[mysqldump]
quick
max_allowed_packet=16M
EOF
配置環境變量
echo “PATH=/usr/local/mysql/bin:$PATH” >> /etc/profile
source /etc/profile
配置啟動腳本
cp …/mysql-8.0.12/support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
centos7系統自啟動腳本
cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
Documentation=man:mysql(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld $MYSQLD_OPTS
LimitNOFILE = 10000
Restart=always
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
啟動MySQL
systemctl start mysqld.service
修改root密碼:使用WITH指定認證方式
mysql -uroot
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密碼’;
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH caching_sha2_password BY ‘你的密碼’;
查看密碼字段和加密方式
select host, user, authentication_string, plugin from user;
2、yum存儲庫安裝MySQL
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum localinstall mysql80-community-release-el7-1.noarch.rpm
yum repolist enabled|grep “mysql.-community.”
yum repolist all|grep mysql
yum install mysql-community-server
systemctl enable mysqld
systemctl start mysqld
netstat -lntup|grep 3306
查看隨機生成的密碼
grep ‘temporary password’ /var/log/mysqld.log
mysql -uroot -p
修改密碼,密碼必須要由大小寫字母、數字和特性字符組成
alter user ‘root’@‘localhost’ identified by ‘PJY@123.com’;
select version();
總結
以上是生活随笔為你收集整理的【教程】Linux下MySQL 8.0安装配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【收藏】Linux系统常用命令速查手册(
- 下一篇: 【教程】超详细的虚拟无线控制器安装教程