#解壓mysql
tar -zxf mysql-5.7.27-el7-x86_64.tar.gz -C /usr/local/sql
#重命名數據庫
cd /usr/local/socket
mv mysql-5.7.27-el7-x86_64/ mysqlcode
cd mysql/server
mkdir datablog
[root@airflow mysql]# groupadd mysqlip
[root@airflow mysql]# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql/ci
#useradd -r參數表示mysql用戶是系統用戶,不可用於登陸系統unicode
chown -R mysql:mysql /usr/local/mysql/
./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
cp -a ./support-files/mysql.server /etc/init.d/mysqld
vi my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
symbolic-links=0
max_connections=200
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=32M
explicit_defaults_for_timestamp=true
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
注意:mysql鏈接localhost一般經過一個Unix域套接字文件進行,通常是/tmp/mysql.sock,這個socket路徑不要修改,否則連本地mysql的時候回報錯:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
由於my.cnf中配置了log-error、pid-file路徑,所以須要在/var/log/、/var/run/建立mysql目錄,而且給mysql用戶所有的權限(chmod)
chmod -R 777 /var/log/mysql/
chmod -R 777 /var/run/mysql/
不然啓動會報錯,以下圖
service mysqld start
cat /root/.mysql_secret
SET PASSWORD FOR 'root'@localhost=PASSWORD('123456');
vi /etc/profile
增長以下配置:
export PATH=$PATH:/usr/local/mysql/bin
當即生效
source /etc/profile
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list
若是看到mysql的服務,而且3,4,5都是on的話則成功,若是是off,則鍵入
chkconfig --level 345 mysqld on
而後重啓電腦
reboot
查看mysql運行狀態
service mysqld status
mysql -u root -p
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
[mysqld]
socket=/var/lib/mysql/mysql.sock
port = 3306
basedir=/softwares/mysql_5727
datadir=/softwares/mysql_5727/data
max_connections=200
character-set-server=utf8mb4
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=32M
explicit_defaults_for_timestamp=true
若是您以爲此文章對您有幫助,請點擊右下方【推薦】讓更多人看到,thanks!