CentOS7.X原始碼安裝MySQL-5.7.18
mysql資料庫安裝及配置
-
安裝前的準備
yum install vim git gcc gcc-c++ wget make cmake automake autoconf libaio libtool net-tools bison-devel libaio-devel ncurses-devel perl-Data-Dumper -y
-
下載boost_1_59_0
cd /usr/local wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
-
下載mysql-5.7.18
cd /root wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18.tar.gz tar -zxvf mysql-5.7.18.tar.gz cd mysql-5.7.18
-
執行cmake
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_SYSTEMD=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local -DDEFAULT_CHARSET=utf8mb4 make make install
-
新增mysql使用者
useradd -s /sbin/nologin -M mysql
-
建立資料檔案目錄、所屬組、使用者改為mysql
mkdir /data/ mkdir /data/mysql/ chown -R mysql:mysql /etc/my.cnf chown -R mysql:mysql /data/mysql/ chown -R mysql:mysql /var/*/mysql* chown -R mysql:mysql /usr/local/mysql/
-
修改SELinux
vim /etc/sysconfig/selinux SELINUX=permissive ESC :wq setenforce 0
-
my.cnf詳細配置
vim /etc/my.cnf [client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] datadir=/data/mysql character-set-server=utf8mb4 init_connect=`SET NAMES utf8mb4` collation-server=utf8mb4_unicode_ci character-set-client-handshake=FALSE symbolic-links=0 log-error=/var/log/mysqld.log socket=/var/lib/mysql/mysql.sock pid-file=/var/run/mysqld/mysqld.pid secure_file_priv=/var/lib/mysql-files server-id=1 binlog-format=Row log-bin=/data/mysql/mysql-bin sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION ESC :wq
-
初始化資料庫配置
# --initialize-insecure引數為不安全的初始化方案,建議使用--initialize引數 # 以下程式碼執行完之後,會在/data/mysql/mysql-error.log儲存初始密碼 su mysql su mysql !!! su mysql !!! /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql # 檢視初始密碼 cat /var/lib/mysql/mysql.log|grep password # ssh連線mysql,如果對ssh不瞭解,不要這樣做 /usr/local/mysql/bin/mysql_ssl_rsa_setup --initialize --user=mysql vim /etc/my.cnf [client] port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 slow_query_log = 1 long_query_time = 1 socket = /tmp/mysql.sock basedir = /usr/local/mysql datadir = /data/mysql pid-file = /data/mysql/mysql.pid log_error = /data/mysql/mysql-error.log slow_query_log_file = /data/mysql/mysql-slow.log default_storage_engine = InnoDB [mysqld_safe] log-error=/data/mysql/mysql.log pid-file=/data/mysql/mysqld.pid ESC :wq
-
新增mysqld.service
exit cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
-
mysqld.service詳細配置
vim /usr/lib/systemd/system/mysqld.service # 將下面的配置覆蓋整個檔案內容 [Unit] Description=開機啟動MySQL. After=default.target network.target syslog.target [Service] User=mysql Group=mysql Type=forking PIDFile=/data/mysql/mysqld.pid TimeoutSec=0 PermissionsStartOnly=true ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/data/mysql/mysql.pid $MYSQLD_OPTS EnvironmentFile=-/etc/sysconfig/mysql LimitNOFILE = 5000 Restart=on-failure RestartPreventExitStatus=1 PrivateTmp=false [Install] WantedBy=multi-user.target ESC :wq
-
啟用mysqld.service
systemctl enable mysqld systemctl start mysqld systemctl daemon-reload
-
測試配置是否正確,沒有任何輸出則表示一切正常
/usr/local/mysql/bin/mysqld_pre_systemd
-
資料檔案所屬使用者修改為mysql(如果‘初始化資料庫配置’時完全按文件進行,可不執行本步驟,不確定則執行)
chown -R mysql:mysql /data/mysql/
-
啟動mysql
systemctl enable mysqld systemctl start mysqld
-
新增mysql到mysql使用者環境變數
su mysql vim /home/mysql/.bash_profile PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/mysql/bin ESC :wq source /home/mysql/.bash_profile
-
嘗試連線mysql
# mysql預設使用者為root mysql -u root -p password:************** #修改root[DB使用者]初始密碼 SET PASSWORD=PASSWORD(`**************`); show databases; use mysql; show tables; select * from user G;
-
測試啟動、停止、重啟mysql
#啟用並啟動 systemctl enable mysqld systemctl start mysqld #禁用並關閉 systemctl disable mysqld systemctl stop mysqld #啟用並重新啟動 systemctl enable mysqld systemctl restart mysqld
-
設定外部訪問密碼
# 資料庫名-萬用字元及格式: *[允許操作所有資料庫] %pay%[允許操作名字包含`pay`的資料庫] mydatabase[僅允許操作`mydatabase`資料庫] # 表名-萬用字元及格式: *[允許操作所有表] %pay%[允許操作名字包含`pay`的表] mytable[僅允許操作`mytable`表] # ip地址-萬用字元及格式: %/0.0.0.0[允許任意IP訪問] xxx.xxx.xxx.xxx[僅限公網訪問] 192.168.x.xxx[僅限區域網訪問] localhost/127.0.0.1/::1[僅限本機訪問] # 資料庫授權格式 GRANT 許可權名 ON 資料庫名.資料表名 TO `資料使用者`@`訪問IP` IDENTIFIED BY `使用者密碼` WITH GRANT OPTION; # 為任意資料庫表 任意操作 分配root使用者,僅限本地訪問 GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED BY `**************` WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO `root`@`127.0.0.1` IDENTIFIED BY `**************` WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO `root`@`::1` IDENTIFIED BY `**************` WITH GRANT OPTION; # 為任意資料庫表 任意操作 分配mysql使用者,任意IP訪問(安裝除錯階段、本地開發使用,用後即刪) GRANT ALL PRIVILEGES ON *.* TO `mysql`@`%` IDENTIFIED BY `**************` WITH GRANT OPTION; # 為任意資料庫表 增刪改查 分配單獨使用者,為不同的業務分配專屬使用者 GRANT INSERT ON *.* TO `insert1`@`127.0.0.1` IDENTIFIED BY `**************` WITH GRANT OPTION; GRANT DELETE ON *.* TO `delete1`@`127.0.0.1` IDENTIFIED BY `**************` WITH GRANT OPTION; GRANT UPDATE ON *.* TO `update1`@`127.0.0.1` IDENTIFIED BY `**************` WITH GRANT OPTION; GRANT SELECT ON *.* TO `select1`@`127.0.0.1` IDENTIFIED BY `**************` WITH GRANT OPTION; # 重新整理許可權 FLUSH PRIVILEGES;
- 領支付寶紅包支援作者
相關文章
- CentOS7.X安裝NginxCentOSNginx
- CentOS7.X安裝postgresql-10.3CentOSSQL
- CentOS7.X安裝elasticsearch-5.6.2CentOSElasticsearch
- CentOS7.X安裝RabbitMQ-3.6.10CentOSMQ
- Centos7.X安裝DB210.5CentOSDB2
- Centos7.x環境下 安裝DiszzCentOS
- 原始碼安裝openresty原始碼REST
- nginx原始碼安裝Nginx原始碼
- 原始碼安裝postgresql原始碼SQL
- Nginx 原始碼安裝Nginx原始碼
- 原始碼安裝GO原始碼Go
- PostgreSQL 10.12 安裝系列 - 原始碼安裝SQL原始碼
- 【推薦 - 原始碼安裝】nginx - 安裝原始碼Nginx
- yum安裝與原始碼安裝比較原始碼
- Mysql for Linux安裝配置之—— 原始碼安裝MySqlLinux原始碼
- linux安裝python3(原始碼安裝)LinuxPython原始碼
- MySQL 5.7.28 原始碼安裝MySql原始碼
- paramiko 2.4.1原始碼安裝原始碼
- macbook 原始碼安裝 redisMac原始碼Redis
- macbook 原始碼安裝 nginxMac原始碼Nginx
- docker原始碼安裝NginxDocker原始碼Nginx
- 【PG安裝】postgresql10 for linux 原始碼安裝SQLLinux原始碼
- 連網安裝mysql與原始碼安裝mysqlMySql原始碼
- mysql5.5.20原始碼安裝MySql原始碼
- EOS原始碼分析(1)安裝原始碼
- PostgreSQL-原始碼安裝(一)SQL原始碼
- 原始碼編譯安裝Redis原始碼編譯Redis
- openeuler原始碼安裝Postgresql 16原始碼SQL
- 原始碼安裝Nginx和PHP原始碼NginxPHP
- 原始碼包安裝過程原始碼
- linux-原始碼的編譯安裝和解除安裝Linux原始碼編譯
- Greenplum_原始碼編譯安裝和RPM包安裝原始碼編譯
- samba原始碼安裝及除錯Samba原始碼除錯
- CentOS7原始碼安裝NginxCentOS原始碼Nginx
- 原始碼編譯安裝的原理原始碼編譯
- 從原始碼安裝GDB-8.1原始碼
- 【轉】MySQL原始碼編譯安裝MySql原始碼編譯
- CentOS 7 原始碼安裝 Zabbix 6.0CentOS原始碼