本安裝對應的OS爲安裝時默認最小軟件包選擇。php
檢查操做系統版本號html
[root@MySQL ~]# uname -a Linux MySQL.NODE01 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
官網下載對應的版本(默認社區下載最新發布版本,可在Archives頁面下載以前的小版本)java
官網RPM安裝參考文檔路徑:python
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html
配置yum源,安裝基礎依賴的軟件包如(perl)mysql
掛載操做系統光驅linux
[root@MySQL MySQL ~]# mount -t iso9660 /dev/cdrom /mnt/ [root@MySQL rpmpackages]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos_mysql-root 48G 2.0G 46G 5% / devtmpfs 903M 0 903M 0% /dev tmpfs 913M 0 913M 0% /dev/shm tmpfs 913M 8.6M 904M 1% /run tmpfs 913M 0 913M 0% /sys/fs/cgroup /dev/sda1 497M 125M 373M 25% /boot tmpfs 183M 0 183M 0% /run/user/0 /dev/sr0 4.1G 4.1G 0 100% /mnt 修改/etc/yum.repos.d/CentOS-Base.repo文件配置本地yum源 註釋mirrorlist同時修改baseurl爲掛載ISO光盤的目錄 [root@MySQL ~]# vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra baseurl=file:///mnt/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 清理配置 [root@MySQL ~]# yum clean all 檢查yum配置是否成功 [root@MySQL ~]# yum list 檢查系統已安裝的mysql相關軟件 [root@MySQL yum.repos.d]# yum search mysql Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile ======================================= N/S matched: mysql ================================ MySQL-python.x86_64 : An interface to MySQL akonadi-mysql.x86_64 : Akonadi MySQL backend support dovecot-mysql.x86_64 : MySQL back end for dovecot libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi mysql-connector-java.noarch : Official JDBC driver for MySQL mysql-connector-odbc.x86_64 : ODBC driver for MySQL pcp-pmda-mysql.x86_64 : Performance Co-Pilot (PCP) metrics for MySQL perl-DBD-MySQL.x86_64 : A MySQL interface for Perl php-mysql.x86_64 : A module for PHP applications that use MySQL databases qt-mysql.x86_64 : MySQL driver for Qt's SQL classes qt3-MySQL.x86_64 : MySQL drivers for Qt 3's SQL classes rsyslog-mysql.x86_64 : MySQL support for rsyslog mariadb.x86_64 : A community developed branch of MySQL mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients 卸載mariadb帶的mysql-libs [root@MySQL rpmpackages]# yum remove mysql-libs Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be erased --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Running transaction check ---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================= Package Arch Version Repository Size ========================================================================================================= Removing: mariadb-libs x86_64 1:5.5.44-2.el7.centos @anaconda 4.4 M Removing for dependencies: postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M Transaction Summary ========================================================================================================= Remove 1 Package (+1 Dependent package) Installed size: 17 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : 2:postfix-2.10.1-6.el7.x86_64 1/2 Erasing : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 2/2 Verifying : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 1/2 Verifying : 2:postfix-2.10.1-6.el7.x86_64 2/2 Removed: mariadb-libs.x86_64 1:5.5.44-2.el7.centos Dependency Removed: postfix.x86_64 2:2.10.1-6.el7 Complete! 檢查MySQL相關的全部目錄,並清除 [root@MySQL ~]# rpm -qa | grep -i mysql [root@MySQL ~]# find / -name mysql /usr/lib64/mysql /usr/share/mysql [root@MySQL ~]# rm -rf /usr/lib64/mysql [root@MySQL ~]# rm -rf /usr/share/mysql [root@MySQL ~]# ls /etc/my* /etc/my.cnf /etc/my.cnf.d: mysql-clients.cnf [root@MySQL ~]# rm -rf /etc/my.cnf [root@MySQL ~]# rm -rf /etc/my.cnf.d 安裝perl軟件包 [root@MySQL ~]# yum install perl Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package perl.x86_64 4:5.16.3-286.el7 will be installed --> Processing Dependency: perl-libs = 4:5.16.3-286.el7 for package: 4:perl-5.16.3-286.el7.x86_64 --> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-286.el7.x86_64 --> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-286.el7.x86_64 --> Processing Dependency: perl-macros for package: 4:perl-5.16.3-286.el7.x86_64 --> Processing Dependency: perl-libs for package: 4:perl-5.16.3-286.el7.x86_64 …… Transaction Summary ================================================================================================== Install 1 Package (+26 Dependent packages) Total download size: 11 M Installed size: 36 M Is this ok [y/d/N]: y Downloading packages: warning: /mnt/Packages/perl-5.16.3-286.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for perl-5.16.3-286.el7.x86_64.rpm is not installed -------------------------------------------------------------------------------------------------- Total 33 MB/s | 11 MB 00:00:00 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-2.1511.el7.centos.2.10.x86_64 (@anaconda) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Is this ok [y/N]: y Running transaction check …… Installed: perl.x86_64 4:5.16.3-286.el7 Dependency Installed: perl-Carp.noarch 0:1.26-244.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-2.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-Pod-Escapes.noarch 1:1.04-286.el7 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-3.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-286.el7 perl-macros.x86_64 4:5.16.3-286.el7 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 Complete! 安裝net-tools [root@MySQL rpmpackages]# yum install net-tools Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================= Package Arch Version Repository Size ========================================================================================================= Installing: net-tools x86_64 2.0-0.17.20131004git.el7 base 304 k Transaction Summary ========================================================================================================= Install 1 Package Total download size: 304 k Installed size: 917 k Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : net-tools-2.0-0.17.20131004git.el7.x86_64 1/1 Verifying : net-tools-2.0-0.17.20131004git.el7.x86_64 1/1 Installed: net-tools.x86_64 0:2.0-0.17.20131004git.el7 Complete! 解壓安裝包 [root@MySQL ~]# cd /rpmpackages/ [root@MySQL rpmpackages]# ls mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar [root@MySQL rpmpackages]# tar -xf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar [root@MySQL rpmpackages]# ls mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar mysql-community-client-5.7.17-1.el7.x86_64.rpm mysql-community-common-5.7.17-1.el7.x86_64.rpm mysql-community-devel-5.7.17-1.el7.x86_64.rpm mysql-community-embedded-5.7.17-1.el7.x86_64.rpm mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm mysql-community-libs-5.7.17-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm mysql-community-server-5.7.17-1.el7.x86_64.rpm mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm mysql-community-test-5.7.17-1.el7.x86_64.rpm 安裝MySQL的RPM包 [root@MySQL rpmpackages]# yum install mysql-community-server-5.7.17-1.el7.x86_64.rpm mysql-community-libs-5.7.17-1.el7.x86_64.rpm mysql-community-embedded-5.7.17-1.el7.x86_64.rpm mysql-community-devel-5.7.17-1.el7.x86_64.rpm mysql-community-common-5.7.17-1.el7.x86_64.rpm mysql-community-client-5.7.17-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-server-5.7.17-1.el7.x86_64.rpm: mysql-community-server-5.7.17-1.el7.x86_64 …… Total size: 1.0 G Installed size: 1.0 G Is this ok [y/d/N]: y Downloading packages: Running transaction check …… Installed: mysql-community-client.x86_64 0:5.7.17-1.el7 mysql-community-common.x86_64 0:5.7.17-1.el7 mysql-community-devel.x86_64 0:5.7.17-1.el7 mysql-community-embedded.x86_64 0:5.7.17-1.el7 mysql-community-libs.x86_64 0:5.7.17-1.el7 mysql-community-server.x86_64 0:5.7.17-1.el7 Complete! 啓動mysqld服務 [root@MySQL ~]# service mysqld start Redirecting to /bin/systemctl start mysqld.service [root@MySQL ~]# service mysqld status Redirecting to /bin/systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2017-04-18 15:46:36 CST; 34s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 2839 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 2764 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 2841 (mysqld) CGroup: /system.slice/mysqld.service └─2841 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Apr 18 15:46:33 MySQL.NODE01 systemd[1]: Starting MySQL Server... Apr 18 15:46:36 MySQL.NODE01 systemd[1]: Started MySQL Server. 查找安裝過程當中生成的臨時密碼,臨時密碼是mysqld服務啓動的時候生成的。 [root@MySQL ~]# grep 'temporary password' /var/log/mysqld.log 2017-04-18T07:46:33.603394Z 1 [Note] A temporary password is generated for root@localhost: ot<wkuhM_11M 採用臨時密碼登陸 [root@MySQL ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.17 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> 修改root用戶密碼 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'System@123456'; Query OK, 0 rows affected (0.00 sec) mysql> 再用新密碼登陸測試是否正常登陸 [root@MySQL ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.17 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
默認的目錄信息列表:git
安裝完rpm包後能夠配置/etc/my.cnf文件,再初始化數據庫,將數據庫安裝到我的指定的目錄中。sql
以上安裝完成後僅能在服務器本地登陸MySQL,若是須要遠程登陸MySQL服務器則須要進行以下設置。數據庫
關閉防火牆,CentOS7的防火牆默認是firewall,若是安全控制不嚴格能夠直接關閉firewal服務,若是執行嚴格安全要求能夠配置iptables服務,將MySQL端口開放,如下爲詳細配置過程。centos
#查看ifrewall服務狀態 [root@MySQL ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Apr 26 09:39:33 MySQL.NODE01 systemd[1]: Starting firewalld - dynamic firewall daemon... Apr 26 09:39:36 MySQL.NODE01 systemd[1]: Started firewalld - dynamic firewall daemon. May 03 09:41:08 MySQL.NODE01 systemd[1]: Stopping firewalld - dynamic firewall daemon... May 03 09:41:09 MySQL.NODE01 systemd[1]: Stopped firewalld - dynamic firewall daemon. [root@MySQL ~]# firewall-cmd --state not running #關閉firewall服務 [root@MySQL ~]# systemctl stop firewalld.service [root@MySQL ~]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service. #安裝iptables服務(centos默認最小沒有安裝) [root@MySQL ~]# yum install -y iptables-services Loaded plugins: fastestmirror base | 3.6 kB 00:00:00 base-source …… Installed: iptables-services.x86_64 0:1.4.21-16.el7 Complete! #查看安裝的iptables軟件 [root@MySQL ~]# rpm -qa | grep -i iptables iptables-1.4.21-16.el7.x86_64 iptables-services-1.4.21-16.el7.x86_64 #配置開放端口(在22下增長,不要在末尾增長) [root@MySQL ~]# vi /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT #重啓iptables服務器 [root@MySQL ~]# systemctl restart iptables.service #設置爲開啓自啓動 [root@MySQL ~]# systemctl enable iptables.service Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service. #查看服務狀態 [root@MySQL ~]# systemctl --state iptables.service 0 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'. [root@MySQL ~]# systemctl status iptables.service ● iptables.service - IPv4 firewall with iptables Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled) Active: active (exited) since Wed 2017-05-03 09:52:16 CST; 2min 37s ago Main PID: 29362 (code=exited, status=0/SUCCESS) May 03 09:52:15 MySQL.NODE01 systemd[1]: Starting IPv4 firewall with iptables... May 03 09:52:16 MySQL.NODE01 iptables.init[29362]: iptables: Applying firewall rules: [ OK ] May 03 09:52:16 MySQL.NODE01 systemd[1]: Started IPv4 firewall with iptables. #經過遠程客戶端鏈接MySQL正常便可 建立業務用戶並受權,開發遠程訪問MySQL服務器權限。 [root@MySQL ~]# mysql -uroot -p -h 192.168.0.222 Enter password: mysql> grant all privileges on *.* to 'ipems'@'192.168.0.%' identified by 'Aa123456'; ERROR 1045 (28000): Access denied for user 'root'@'192.168.0.%' (using password: YES) #該錯誤還不明確是爲何 [root@MySQL ~]# mysql -uroot -p Enter password: mysql> grant all privileges on *.* to 'ipems'@'192.168.0.%' identified by 'Aa@123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select user,host from user; +-----------+-------------+ | user | host | +-----------+-------------+ | ipems | 192.168.0.% | | mysql.sys | localhost | | root | localhost | +-----------+-------------+ 3 rows in set (0.00 sec) [root@MySQL ~]# mysql -uipems -p -h 192.168.0.222 Enter password: …… Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> 若是MySQL服務器上的防火牆沒有關閉,遠程客戶端鏈接MySQL服務器時會報以下錯誤。 [root@mysql ~]# mysql -uroot -p -h 192.168.0.222 Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.222' (113) MySQL的權限包括用戶密碼和IP地址,若是該用戶配置的訪問IP爲localhost那麼經過IP地址的鏈接也不會成功。 [root@MySQL ~]# mysql -uroot -p -h 192.168.0.222 Enter password: ERROR 1045 (28000): Access denied for user 'root'@'192.168.0.222' (using password: YES) [root@MySQL ~]# mysql -uipems -p -h 192.168.0.222 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.17 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit Bye [root@MySQL ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.17 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select user,host from user; +-----------+-------------+ | user | host | +-----------+-------------+ | ipems | 192.168.0.% | | mysql.sys | localhost | | root | localhost | +-----------+-------------+ 3 rows in set (0.00 sec) 關閉Selinux,修改/etc/selinux/config文件中的SELINUX=」」 爲 disabled,而後重啓。 [root@MySQL ~]# vi /etc/selinux/config SELINUX=disabled
CentOS7的systemctl命令補充說明,CentOS6.5之前查看服務相關信息時經過service命令,在CentOS7中將service和chkconfig命令進行合併,相關服務的信息查看與設置經過systemctl 服務.service命令。
任務 |
舊指令 |
新指令 |
使某服務自動啓動 |
chkconfig –level 3 httpd on |
systemctl enable httpd.service |
使某服務不自動啓動 |
chkconfig –level 3 httpd off |
systemctl disable httpd.service |
檢查服務狀態 |
service httpd status |
systemctl status httpd.service (服務詳細信息) systemctl is-active httpd.service (僅顯示是否 Active) |
顯示全部已啓動的服務 |
chkconfig –list |
systemctl list-units –type=service |
啓動某服務 |
service httpd start |
systemctl start httpd.service |
中止某服務 |
service httpd stop |
systemctl stop httpd.service |
重啓某服務 |
service httpd restart |
systemctl restart httpd.service |
RPM安裝後修改相關目錄信息
關閉服務
systemctl stop mysqld 刪除默認初始化的數據目錄 find / -name mysql rm -rf /var/lib/mysql 清空要存放指定文件的目錄及目錄的全部者 配置my.cnf文件,裏邊配置 [client] socket = /mysqldb/sockandpid/mysql.sock [mysql] default-character-set=utf8 [mysqld] #進程文件路徑 pid-file=/mysqldb/sockandpid/mysql.pid #socket文件徑 socket=/mysqldb/sockandpid/mysql.sock #數據目錄 datadir=/mysqldb/data #錯誤日誌路徑 log-error=/mysqldb/errorlog/error.log #慢查詢日誌路徑 slow_query_log_file=/mysqldb/slowlog/slow-query.log #binlog日誌路徑 server_id=1 log-bin=/mysqldb/binlog/mysql-bin 執行初始化 mysqld --user=mysql --initialize --datadir=/mysqldb/data --basedir=/usr/local/mysql/ 查詢初始化密碼 cat /mysqldb/errorlog/error.log | grep temporary 啓動mysqld服務 systemctl start mysqld 利用初始化的密碼登陸,修改root的密碼,查詢具體參數 mysql -uroot -p alter user 'root'@'localhost' identified by 'System@123456'; mysql> show variables like 'datadir'; +---------------+----------------+ | Variable_name | Value | +---------------+----------------+ | datadir | /mysqldb/data/ | +---------------+----------------+ 1 row in set (0.00 sec) mysql> show variables like 'socket'; +---------------+--------------------------------+ | Variable_name | Value | +---------------+--------------------------------+ | socket | /mysqldb/sockandpid/mysql.sock | +---------------+--------------------------------+ 1 row in set (0.01 sec) mysql> show variables like 'log_bin'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | ON | +---------------+-------+ 1 row in set (0.01 sec) mysql> show variables like 'log_bin%'; +---------------------------------+---------------------------------+ | Variable_name | Value | +---------------------------------+---------------------------------+ | log_bin | ON | | log_bin_basename | /mysqldb/binlog/mysql-bin | | log_bin_index | /mysqldb/binlog/mysql-bin.index | | log_bin_trust_function_creators | OFF | | log_bin_use_v1_row_events | OFF | +---------------------------------+---------------------------------+ 5 rows in set (0.01 sec) mysql> show variables like 'slow_query_log_file'; +---------------------+---------------------------------+ | Variable_name | Value | +---------------------+---------------------------------+ | slow_query_log_file | /mysqldb/slowlog/slow-query.log | +---------------------+---------------------------------+ 1 row in set (0.01 sec) mysql> show variables like 'pid_file'; +---------------+----------------------------+ | Variable_name | Value | +---------------+----------------------------+ | pid_file | /var/run/mysqld/mysqld.pid | +---------------+----------------------------+ 1 row in set (0.01 sec)
下載二進制包 mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz 解壓並整理目錄 gtar -zxf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local cd /usr/local/ mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql 安裝依賴的軟件包 yum -y install libaio 建立用戶用戶組 groupadd -r mysql useradd -r mysql 建立相應目錄並設置目錄權限 mkdir -p /mysqldb/data/ mkdir -p /mysqldb/errorlog/ mkdir -p /mysqldb/slowlog/ mkdir -p /mysqldb/sockandpid/ chown -R mysql.mysql /usr/local/mysql/* chown -R mysql.mysql /mysqldb/data 配置my.cnf文件 [mysqld] #進程文件路徑 pid-file=/mysqldb/sockandpid/mysql.pid #socket文件徑 socket=/mysqldb/sockandpid/mysql.sock #數據目錄 datadir=/mysqldb/data #錯誤日誌路徑 log-error=/mysqldb/errorlog/error.log #慢查詢日誌路徑 slow_query_log_file=/mysqldb/slowlog/slow-query.log #binlog日誌路徑,binlog要與server_id一塊設置不然報錯沒法啓動 server_id=1 log-bin=/mysqldb/binlog/mysql-bin #客戶端的socket,修改socket目錄後每次客戶端登陸都要-S能夠經過此配置解決 [client] socket = /mysqldb/sockandpid/mysql.sock 執行初始化 /usr/local/mysql/bin/mysqld --user=mysql --initialize --datadir=/mysqldb/data --basedir=/usr/local/mysql/ 初始化過程執行時若是配置了errorlog文件,則將相應日誌輸出在errorlog文件中包括臨時生成的密碼,若是沒有這隻errorlog文件則輸出在控制檯。 啓動MySQL服務 cp mysql/support-files/mysql.server /etc/init.d/mysql chmod 755 /etc/init.d/mysql systemctl start mysql 查找初始化的臨時密碼 cat /mysqldb/errorlog/error.log | grep temporary 初始登陸,修改root用戶密碼 mysql/bin/mysql -uroot -p -S /mysqldb/sockandpid/mysql.sock mysql> alter user 'root'@'localhost' identified by 'Aa123456789'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) 參考資料 https://jingyan.baidu.com/article/5d368d1ed79ef23f60c05737.html http://blog.csdn.net/wlzjsj/article/details/52289482
sql_mode默認值是空值,在這種設置下是能夠容許一些非法操做的,好比容許一些非法數據的插入。在生產環境必須將這個值設置爲嚴格模式,因此開發、測試環境的數據庫也必需要設置。
sql_mode='ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES'