版本
Linux 5.7.17
依賴
CentOS
yum install libaio libaio-devel
Ubuntu
apt install libaio1 libaio-dev
準備簡單配置檔案
刪除多餘檔案
rm -rf /etc/my.cnf /etc/my.cnf.d /etc/mysql && mkdir -p /etc/mysql
準備配置檔案
vim /etc/mysql/my.cnf
複製如下內容
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
# Path to installation directory. All paths are usually resolved relative to this
basedir="/usr/local/mysql"
# Path to the database root
datadir="/usr/local/mysql/data"
# PID file name
pid-file = mysqld.pid
# The default character set that will be used when a new schema or table is created and no character set is defined
character-set-server=utf8mb4
# encode
collation-server = utf8mb4_unicode_ci
init_connect = 'SET collation_connection=utf8mb4_unicode_ci'
init_connect = 'SET NAMES utf8mb4'
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
# Set the SQL mode to strict
sql-mode="NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES"
# General and Slow logging.
log-output=FILE
general-log=0
general_log_file="mysqld.log"
slow-query-log=1
slow_query_log_file="mysqld-slow.log"
# 超過5秒的查詢才被記為慢查詢,建議根據您的環境將long_query_time調短。通常建議設為1-5秒。
long_query_time=5
# Error Logging
log-error="mysqld.err"
# Server Id
#server-id=1
安裝
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf /path/to/mysql-VERSION-OS.tar.gz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize-insecure --user=mysql
bin/mysql_ssl_rsa_setup
cp support-files/mysql.server /etc/init.d/mysqld
設定環境變數
cp /etc/profile /etc/profile.backup
echo "# MySQL PATH" >> /etc/profile
echo "export PATH=$""PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
建立服務檔案
vim /lib/systemd/system/mysqld.service
複製如下內容
[Unit]
Description=MySQL Service
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
ExecReload=/etc/init.d/mysqld restart
ExecStop=/etc/init.d/mysqld stop
PrivateTmp=false
[Install]
WantedBy=multi-user.target
以754的許可權儲存在目錄
chmod 745 /lib/systemd/system/mysqld.service
必須先啟動服務
systemctl start mysqld.service
然後設定密碼
mysqladmin -u root -p password '你的密碼'
Enter password:
# 因為我們是無密碼初始化,直接回車即可。
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
重啟服務生效
systemctl restart mysqld.service
版本
Windows 5.7.17
本作品採用《CC 協議》,轉載必須註明作者和本文連結