CentOS7 安装 MySQL 和简单优化
[0x0]環境及其軟件介紹
- 操作系統:CentOS7.0 純凈版
- MySQL 版本:5.7.16
[0x1]關閉SELinux
SELinux(Security-Enhanced Linux) 是美國國家安全局(NSA)對于強制訪問控制的實現,是 Linux 歷史上最杰出的新安全子系統。在這種訪問控制體系的限制下,進程只能訪問那些在他的任務中所需要文件。SELinux 默認安裝在 Fedora 和 Red Hat Enterprise Linux 上。雖然 SELinux 很好用,但是在多數情況我們還是將其關閉,因為在不了解其機制的情況下使用 SELinux 會導致軟件安裝或者應用部署失敗。
一般如果使用云服務器,已經默認關閉了該服務,如果是虛擬機自己安裝 CentOS 的話,那么需要自己手動關閉。如果不關閉,則影響后面的操作。
[root@virtual data]# getenforce Enforcing [root@virtual data]#
- 永久性關閉
永久性關閉則需要重啟服務器后生效
- 臨時性關閉
臨時性關閉僅對當前有效且立即生效,重啟服務器之后無效。
setenforce 0命令表示設置 selinux 為 permissive 模式(即關閉);
setenforce 1命令表示設置 selinux 為 enforcing 模式(即開啟)
[0x2]下載 MySQL
MySQL 的官網下載地址是http://dev.mysql.com/downloads/mysql/,選擇Red Hat Enterprise Linux / Oracle Linux(因為 CentOS 屬于 RHEL 的一個分支),如下圖所示
然后下面選擇 CentOS7 的全家桶,選擇全家桶比較方便,當安裝的時候如果提示缺少包,一般可以在全家桶里直接找到的。
老套路,可以直接到微云下載(密碼:yv8Fib)。
將下載成功mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar上傳到您的服務器,下面就準備開始安裝了。
[0x3]安裝 MySQL
首先將上傳的 MySQLmysql-5.7.16-1.el7.x86_64.rpm-bundle.tar解壓出來。
? [root@virtual mysql]# ls mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar [root@virtual mysql]# tar xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm mysql-community-devel-5.7.16-1.el7.x86_64.rpm mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm mysql-community-libs-5.7.16-1.el7.x86_64.rpm mysql-community-common-5.7.16-1.el7.x86_64.rpm mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm mysql-community-test-5.7.16-1.el7.x86_64.rpm mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm mysql-community-server-5.7.16-1.el7.x86_64.rpm mysql-community-client-5.7.16-1.el7.x86_64.rpm mysql-community-embedded-5.7.16-1.el7.x86_64.rpm [root@virtual mysql]#[root@virtual mysql]# ls mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar [root@virtual mysql]# tar xvf mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm mysql-community-devel-5.7.16-1.el7.x86_64.rpm mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm mysql-community-libs-5.7.16-1.el7.x86_64.rpm mysql-community-common-5.7.16-1.el7.x86_64.rpm mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm mysql-community-test-5.7.16-1.el7.x86_64.rpm mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm mysql-community-server-5.7.16-1.el7.x86_64.rpm mysql-community-client-5.7.16-1.el7.x86_64.rpm mysql-community-embedded-5.7.16-1.el7.x86_64.rpm [root@virtual mysql]#
安裝 MySQL 數據庫的服務器版本,即mysql-community-server-5.7.16-1.el7.x86_64.rpm,安裝命令這里使用yum localinstall,該命令會自動分析軟件依賴包,非常的方便。
? [root@virtual mysql]# yum localinstall mysql-community-server- mysql-community-server-5.7.16-1.el7.x86_64.rpm mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm [root@virtual mysql]# yum localinstall mysql-community-server-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-server-5.7.16-1.el7.x86_64.rpm: mysql-community-server-5.7.16-1.el7.x86_64 Marking mysql-community-server-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.16-1.el7 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 5.7.16-1.el7 for package: mysql-community-server-5.7.16-1.el7.x86_64 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.yun-idc.com --> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.16-1.el7.x86_64 --> Processing Dependency: net-tools for package: mysql-community-server-5.7.16-1.el7.x86_64 --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.16-1.el7 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 5.7.16-1.el7 for package: mysql-community-server-5.7.16-1.el7.x86_64 --> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.16-1.el7.x86_64 ---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed --> Finished Dependency Resolution Error: Package: mysql-community-server-5.7.16-1.el7.x86_64 (/mysql-community-server-5.7.16-1.el7.x86_64) Requires: mysql-community-common(x86-64) = 5.7.16-1.el7 Error: Package: mysql-community-server-5.7.16-1.el7.x86_64 (/mysql-community-server-5.7.16-1.el7.x86_64) Requires: mysql-community-client(x86-64) >= 5.7.9 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest [root@virtual mysql]#[root@virtual mysql]# yum localinstall mysql-community-server- mysql-community-server-5.7.16-1.el7.x86_64.rpm mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm [root@virtual mysql]# yum localinstall mysql-community-server-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-server-5.7.16-1.el7.x86_64.rpm: mysql-community-server-5.7.16-1.el7.x86_64 Marking mysql-community-server-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.16-1.el7 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 5.7.16-1.el7 for package: mysql-community-server-5.7.16-1.el7.x86_64 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.yun-idc.com --> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.16-1.el7.x86_64 --> Processing Dependency: net-tools for package: mysql-community-server-5.7.16-1.el7.x86_64 --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.16-1.el7 will be installed --> Processing Dependency: mysql-community-common(x86-64) = 5.7.16-1.el7 for package: mysql-community-server-5.7.16-1.el7.x86_64 --> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.16-1.el7.x86_64 ---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed --> Finished Dependency Resolution Error: Package: mysql-community-server-5.7.16-1.el7.x86_64 (/mysql-community-server-5.7.16-1.el7.x86_64) Requires: mysql-community-common(x86-64) = 5.7.16-1.el7 Error: Package: mysql-community-server-5.7.16-1.el7.x86_64 (/mysql-community-server-5.7.16-1.el7.x86_64) Requires: mysql-community-client(x86-64) >= 5.7.9 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest [root@virtual mysql]#
根據上面的錯誤信息可以知道,安裝 MySQL 服務器mysql-community-server-5.7.16-1.el7.x86_64.rpm需要先安裝mysql-community-client(x86-64)軟件,這個時候體現出全家桶的好處,發現全家桶里面帶有這個軟件,所以直接先安裝這個軟件即可。
? [root@virtual mysql]# yum localinstall mysql-community-client-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-client-5.7.16-1.el7.x86_64.rpm: mysql-community-client-5.7.16-1.el7.x86_64 Marking mysql-community-client-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-client.x86_64 0:5.7.16-1.el7 will be installed --> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.16-1.el7.x86_64 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.yun-idc.com --> Finished Dependency Resolution Error: Package: mysql-community-client-5.7.16-1.el7.x86_64 (/mysql-community-client-5.7.16-1.el7.x86_64) Requires: mysql-community-libs(x86-64) >= 5.7.9 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest [root@virtual mysql]#[root@virtual mysql]# yum localinstall mysql-community-client-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-client-5.7.16-1.el7.x86_64.rpm: mysql-community-client-5.7.16-1.el7.x86_64 Marking mysql-community-client-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-client.x86_64 0:5.7.16-1.el7 will be installed --> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.16-1.el7.x86_64 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.yun-idc.com --> Finished Dependency Resolution Error: Package: mysql-community-client-5.7.16-1.el7.x86_64 (/mysql-community-client-5.7.16-1.el7.x86_64) Requires: mysql-community-libs(x86-64) >= 5.7.9 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest [root@virtual mysql]#
套路出來了,根據錯誤信息,很顯然先安裝mysql-community-libs(x86-64),走起:
? [root@virtual mysql]# yum localinstall mysql-community-libs- mysql-community-libs-5.7.16-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm [root@virtual mysql]# yum localinstall mysql-community-libs-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-libs-5.7.16-1.el7.x86_64.rpm: mysql-community-libs-5.7.16-1.el7.x86_64 Marking mysql-community-libs-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be obsoleted --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.yun-idc.com --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be updated ---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be an update ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 Removing mariadb-libs.x86_64 1:5.5.50-1.el7_2 - u due to obsoletes from mysql-community-libs.x86_64 0:5.7.16-1.el7 - u --> Restarting Dependency Resolution with new changes. --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be an update --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.47-1.el7_2 will be an update ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 Removing mariadb-libs.x86_64 1:5.5.47-1.el7_2 - u due to obsoletes from mysql-community-libs.x86_64 0:5.7.16-1.el7 - u --> Restarting Dependency Resolution with new changes. --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.47-1.el7_2 will be an update --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 --> Finished Dependency Resolution Error: Package: mysql-community-libs-5.7.16-1.el7.x86_64 (/mysql-community-libs-5.7.16-1.el7.x86_64) Requires: mysql-community-common(x86-64) >= 5.7.9 Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda) Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit) Removing: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (@anaconda) libmysqlclient.so.18(libmysqlclient_18)(64bit) Obsoleted By: mysql-community-libs-5.7.16-1.el7.x86_64 (/mysql-community-libs-5.7.16-1.el7.x86_64) Not found Updated By: 1:mariadb-libs-5.5.50-1.el7_2.x86_64 (updates) libmysqlclient.so.18(libmysqlclient_18)(64bit) Available: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates) libmysqlclient.so.18(libmysqlclient_18)(64bit) Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda) Requires: libmysqlclient.so.18()(64bit) Removing: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (@anaconda) libmysqlclient.so.18()(64bit) Obsoleted By: mysql-community-libs-5.7.16-1.el7.x86_64 (/mysql-community-libs-5.7.16-1.el7.x86_64) ~libmysqlclient.so.20()(64bit) Updated By: 1:mariadb-libs-5.5.50-1.el7_2.x86_64 (updates) libmysqlclient.so.18()(64bit) Available: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates) libmysqlclient.so.18()(64bit) You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest [root@virtual mysql]#[root@virtual mysql]# yum localinstall mysql-community-libs- mysql-community-libs-5.7.16-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm [root@virtual mysql]# yum localinstall mysql-community-libs-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-libs-5.7.16-1.el7.x86_64.rpm: mysql-community-libs-5.7.16-1.el7.x86_64 Marking mysql-community-libs-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be obsoleted --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.yun-idc.com --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be updated ---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be an update ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 Removing mariadb-libs.x86_64 1:5.5.50-1.el7_2 - u due to obsoletes from mysql-community-libs.x86_64 0:5.7.16-1.el7 - u --> Restarting Dependency Resolution with new changes. --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be an update --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.47-1.el7_2 will be an update ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 Removing mariadb-libs.x86_64 1:5.5.47-1.el7_2 - u due to obsoletes from mysql-community-libs.x86_64 0:5.7.16-1.el7 - u --> Restarting Dependency Resolution with new changes. --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.47-1.el7_2 will be an update --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) >= 5.7.9 for package: mysql-community-libs-5.7.16-1.el7.x86_64 --> Finished Dependency Resolution Error: Package: mysql-community-libs-5.7.16-1.el7.x86_64 (/mysql-community-libs-5.7.16-1.el7.x86_64) Requires: mysql-community-common(x86-64) >= 5.7.9 Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda) Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit) Removing: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (@anaconda) libmysqlclient.so.18(libmysqlclient_18)(64bit) Obsoleted By: mysql-community-libs-5.7.16-1.el7.x86_64 (/mysql-community-libs-5.7.16-1.el7.x86_64) Not found Updated By: 1:mariadb-libs-5.5.50-1.el7_2.x86_64 (updates) libmysqlclient.so.18(libmysqlclient_18)(64bit) Available: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates) libmysqlclient.so.18(libmysqlclient_18)(64bit) Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda) Requires: libmysqlclient.so.18()(64bit) Removing: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (@anaconda) libmysqlclient.so.18()(64bit) Obsoleted By: mysql-community-libs-5.7.16-1.el7.x86_64 (/mysql-community-libs-5.7.16-1.el7.x86_64) ~libmysqlclient.so.20()(64bit) Updated By: 1:mariadb-libs-5.5.50-1.el7_2.x86_64 (updates) libmysqlclient.so.18()(64bit) Available: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates) libmysqlclient.so.18()(64bit) You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest [root@virtual mysql]#
這次出現的錯誤不太一樣,出現了兩個錯誤,一個錯誤仍然提示缺少依賴包,mysql-community-common(x86-64),另外一個錯誤是與mariadb-libs-5.5.44-2.el7.centos.x86_64發生沖突,所以需要卸載這個軟件。
? [root@virtual mysql]# yum remove mariadb-libs Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 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.50-1.el7_2 @updates 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.50-1.el7_2.x86_64 2/2 Verifying : 1:mariadb-libs-5.5.50-1.el7_2.x86_64 1/2 Verifying : 2:postfix-2.10.1-6.el7.x86_64 2/2 Removed: mariadb-libs.x86_64 1:5.5.50-1.el7_2 Dependency Removed: postfix.x86_64 2:2.10.1-6.el7 Complete! [root@virtual mysql]#[root@virtual mysql]# yum remove mariadb-libs Loaded plugins: fastestmirror Resolving Dependencies --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 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.50-1.el7_2 @updates 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.50-1.el7_2.x86_64 2/2 Verifying : 1:mariadb-libs-5.5.50-1.el7_2.x86_64 1/2 Verifying : 2:postfix-2.10.1-6.el7.x86_64 2/2 Removed: mariadb-libs.x86_64 1:5.5.50-1.el7_2 Dependency Removed: postfix.x86_64 2:2.10.1-6.el7 Complete! [root@virtual mysql]#
卸載完成后解決最后一個依賴問題mysql-community-common-5.7.16-1.el7.x86_64.rpm
? [root@virtual mysql]# yum localinstall mysql-community-common-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-common-5.7.16-1.el7.x86_64.rpm: mysql-community-common-5.7.16-1.el7.x86_64 Marking mysql-community-common-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-common.x86_64 0:5.7.16-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================= Package Arch Version Repository Size ========================================================================================================================================================= Installing: mysql-community-common x86_64 5.7.16-1.el7 /mysql-community-common-5.7.16-1.el7.x86_64 2.5 M Transaction Summary ========================================================================================================================================================= Install 1 Package Total size: 2.5 M Installed size: 2.5 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql-community-common-5.7.16-1.el7.x86_64 1/1 Verifying : mysql-community-common-5.7.16-1.el7.x86_64 1/1 Installed: mysql-community-common.x86_64 0:5.7.16-1.el7 Complete! [root@virtual mysql]#[root@virtual mysql]# yum localinstall mysql-community-common-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-common-5.7.16-1.el7.x86_64.rpm: mysql-community-common-5.7.16-1.el7.x86_64 Marking mysql-community-common-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-common.x86_64 0:5.7.16-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================= Package Arch Version Repository Size ========================================================================================================================================================= Installing: mysql-community-common x86_64 5.7.16-1.el7 /mysql-community-common-5.7.16-1.el7.x86_64 2.5 M Transaction Summary ========================================================================================================================================================= Install 1 Package Total size: 2.5 M Installed size: 2.5 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql-community-common-5.7.16-1.el7.x86_64 1/1 Verifying : mysql-community-common-5.7.16-1.el7.x86_64 1/1 Installed: mysql-community-common.x86_64 0:5.7.16-1.el7 Complete! [root@virtual mysql]#
接下來就是倒著安裝相關依賴,首先安裝mysql-community-libs-5.7.16-1.el7.x86_64.rpm
? [root@virtual mysql]# yum localinstall mysql-community-libs-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-libs-5.7.16-1.el7.x86_64.rpm: mysql-community-libs-5.7.16-1.el7.x86_64 Marking mysql-community-libs-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================= Package Arch Version Repository Size ========================================================================================================================================================= Installing: mysql-community-libs x86_64 5.7.16-1.el7 /mysql-community-libs-5.7.16-1.el7.x86_64 9.4 M Transaction Summary ========================================================================================================================================================= Install 1 Package Total size: 9.4 M Installed size: 9.4 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql-community-libs-5.7.16-1.el7.x86_64 1/1 Verifying : mysql-community-libs-5.7.16-1.el7.x86_64 1/1 Installed: mysql-community-libs.x86_64 0:5.7.16-1.el7 Complete! [root@virtual mysql]#[root@virtual mysql]# yum localinstall mysql-community-libs-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-libs-5.7.16-1.el7.x86_64.rpm: mysql-community-libs-5.7.16-1.el7.x86_64 Marking mysql-community-libs-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================= Package Arch Version Repository Size ========================================================================================================================================================= Installing: mysql-community-libs x86_64 5.7.16-1.el7 /mysql-community-libs-5.7.16-1.el7.x86_64 9.4 M Transaction Summary ========================================================================================================================================================= Install 1 Package Total size: 9.4 M Installed size: 9.4 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql-community-libs-5.7.16-1.el7.x86_64 1/1 Verifying : mysql-community-libs-5.7.16-1.el7.x86_64 1/1 Installed: mysql-community-libs.x86_64 0:5.7.16-1.el7 Complete! [root@virtual mysql]#
繼續安裝mysql-community-client-5.7.16-1.el7.x86_64.rpm
? [root@virtual mysql]# yum localinstall mysql-community-client-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-client-5.7.16-1.el7.x86_64.rpm: mysql-community-client-5.7.16-1.el7.x86_64 Marking mysql-community-client-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-client.x86_64 0:5.7.16-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================= Package Arch Version Repository Size ========================================================================================================================================================= Installing: mysql-community-client x86_64 5.7.16-1.el7 /mysql-community-client-5.7.16-1.el7.x86_64 106 M Transaction Summary ========================================================================================================================================================= Install 1 Package Total size: 106 M Installed size: 106 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql-community-client-5.7.16-1.el7.x86_64 1/1 Verifying : mysql-community-client-5.7.16-1.el7.x86_64 1/1 Installed: mysql-community-client.x86_64 0:5.7.16-1.el7 Complete! [root@virtual mysql]#[root@virtual mysql]# yum localinstall mysql-community-client-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-client-5.7.16-1.el7.x86_64.rpm: mysql-community-client-5.7.16-1.el7.x86_64 Marking mysql-community-client-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-client.x86_64 0:5.7.16-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================================================================================= Package Arch Version Repository Size ========================================================================================================================================================= Installing: mysql-community-client x86_64 5.7.16-1.el7 /mysql-community-client-5.7.16-1.el7.x86_64 106 M Transaction Summary ========================================================================================================================================================= Install 1 Package Total size: 106 M Installed size: 106 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql-community-client-5.7.16-1.el7.x86_64 1/1 Verifying : mysql-community-client-5.7.16-1.el7.x86_64 1/1 Installed: mysql-community-client.x86_64 0:5.7.16-1.el7 Complete! [root@virtual mysql]#
word 的天哪,終于到了安裝mysql-community-server-5.7.16-1.el7.x86_64.rpm的時候了。
? [root@virtual mysql]# yum localinstall mysql-community-server-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-server-5.7.16-1.el7.x86_64.rpm: mysql-community-server-5.7.16-1.el7.x86_64 Marking mysql-community-server-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.16-1.el7 will be installed --> Processing Dependency: net-tools for package: mysql-community-server-5.7.16-1.el7.x86_64 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.yun-idc.com --> 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: mysql-community-server x86_64 5.7.16-1.el7 /mysql-community-server-5.7.16-1.el7.x86_64 691 M Installing for dependencies: net-tools x86_64 2.0-0.17.20131004git.el7 base 304 k Transaction Summary ========================================================================================================================================================= Install 1 Package (+1 Dependent package) Total size: 691 M Total download size: 304 k Installed size: 692 M Is this ok [y/d/N]: y Downloading packages: net-tools-2.0-0.17.20131004git.el7.x86_64.rpm | 304 kB 00:00:06 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : net-tools-2.0-0.17.20131004git.el7.x86_64 1/2 Installing : mysql-community-server-5.7.16-1.el7.x86_64 2/2 Verifying : mysql-community-server-5.7.16-1.el7.x86_64 1/2 Verifying : net-tools-2.0-0.17.20131004git.el7.x86_64 2/2 Installed: mysql-community-server.x86_64 0:5.7.16-1.el7 Dependency Installed: net-tools.x86_64 0:2.0-0.17.20131004git.el7 Complete! [root@virtual mysql]#[root@virtual mysql]# yum localinstall mysql-community-server-5.7.16-1.el7.x86_64.rpm Loaded plugins: fastestmirror Examining mysql-community-server-5.7.16-1.el7.x86_64.rpm: mysql-community-server-5.7.16-1.el7.x86_64 Marking mysql-community-server-5.7.16-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql-community-server.x86_64 0:5.7.16-1.el7 will be installed --> Processing Dependency: net-tools for package: mysql-community-server-5.7.16-1.el7.x86_64 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.yun-idc.com --> 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: mysql-community-server x86_64 5.7.16-1.el7 /mysql-community-server-5.7.16-1.el7.x86_64 691 M Installing for dependencies: net-tools x86_64 2.0-0.17.20131004git.el7 base 304 k Transaction Summary ========================================================================================================================================================= Install 1 Package (+1 Dependent package) Total size: 691 M Total download size: 304 k Installed size: 692 M Is this ok [y/d/N]: y Downloading packages: net-tools-2.0-0.17.20131004git.el7.x86_64.rpm | 304 kB 00:00:06 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : net-tools-2.0-0.17.20131004git.el7.x86_64 1/2 Installing : mysql-community-server-5.7.16-1.el7.x86_64 2/2 Verifying : mysql-community-server-5.7.16-1.el7.x86_64 1/2 Verifying : net-tools-2.0-0.17.20131004git.el7.x86_64 2/2 Installed: mysql-community-server.x86_64 0:5.7.16-1.el7 Dependency Installed: net-tools.x86_64 0:2.0-0.17.20131004git.el7 Complete! [root@virtual mysql]#
至此 MySQL 的服務器軟件安裝完畢,并且一并的安裝了 MySQL 客戶端軟件。
[0x4]啟動 MySQL
默認安裝完成后可以檢查下 MySQL 是否啟動了。
? [root@virtual mysql]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: inactive (dead) [root@virtual mysql]#[root@virtual mysql]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: inactive (dead) [root@virtual mysql]#
Active: inactive (dead)表示沒啟動,所以先啟動 MySQL 服務。
? [root@virtual mysql]# systemctl start mysqld [root@virtual mysql]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2016-11-23 21:36:10 CST; 31s ago Process: 12769 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 12752 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 12773 (mysqld) CGroup: /system.slice/mysqld.service └─12773 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Nov 23 21:36:09 virtual.m1 systemd[1]: Starting MySQL Server... Nov 23 21:36:10 virtual.m1 systemd[1]: Started MySQL Server. [root@virtual mysql]#[root@virtual mysql]# systemctl start mysqld [root@virtual mysql]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2016-11-23 21:36:10 CST; 31s ago Process: 12769 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 12752 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 12773 (mysqld) CGroup: /system.slice/mysqld.service └─12773 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Nov 23 21:36:09 virtual.m1 systemd[1]: Starting MySQL Server... Nov 23 21:36:10 virtual.m1 systemd[1]: Started MySQL Server. [root@virtual mysql]#
Active: active (running)表示啟動成功了。
[0x5]登錄 MySQL
好像 MySQL 每個版本對于 root 的初始密碼存放目錄有變更,MySQL5.7 的 root 初始密碼位置在/var/log/mysqld.log,查看初始密碼
? [root@virtual mysql]# cat /var/log/mysqld.log | grep 'password' 2016-11-23T13:35:47.379026Z 1 [Note] A temporary password is generated for root@localhost: 8Elr*VgB7I?E 2016-11-23T13:36:08.112362Z 0 [Note] Shutting down plugin 'validate_password' 2016-11-23T13:36:09.489444Z 0 [Note] Shutting down plugin 'sha256_password' 2016-11-23T13:36:09.489450Z 0 [Note] Shutting down plugin 'mysql_native_password' [root@virtual mysql]#[root@virtual mysql]# cat /var/log/mysqld.log | grep 'password' 2016-11-23T13:35:47.379026Z 1 [Note] A temporary password is generated for root@localhost: 8Elr*VgB7I?E 2016-11-23T13:36:08.112362Z 0 [Note] Shutting down plugin 'validate_password' 2016-11-23T13:36:09.489444Z 0 [Note] Shutting down plugin 'sha256_password' 2016-11-23T13:36:09.489450Z 0 [Note] Shutting down plugin 'mysql_native_password' [root@virtual mysql]#
有了 root 初始密碼就可以登錄了。
? [root@virtual mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.16 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@virtual mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.16 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>
這個時候還不能正常使用 MySQL,會提示先修改 root 密碼。
? mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql>mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql>
以前的 password()函數將會被拋棄,官方建議使用下面的命令來修改密碼ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';;同時,如果你設置的密碼過于簡單也會報錯。
? mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql>mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql>
對于 MySQL5.7 用戶的密碼規則大致如下:
- 長度要大于 8
- 同時要有數字,大小寫,特殊字符
也可以暫時不在這里設置 root 密碼,下面的安裝優化里也會涉及到 root 密碼的修改。
PS:MySQL5.6 的 root 初始密碼位置/root/.mysql_secret
[0x6]加強 MySQL 安全
默認安裝完 MySQL 服務器之后,一般需要執行這個腳本mysql_secure_installation,這里就會涉及到 root 的密碼修改。
? [root@virtual mysql]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: Sorry, passwords do not match. New password: Re-enter new password: The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! [root@virtual mysql]#[root@virtual mysql]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: Sorry, passwords do not match. New password: Re-enter new password: The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! [root@virtual mysql]#
下面列出mysql_secure_installation做的事情
- Set root password? [Y/n] Y
- Remove anonymous users? [Y/n] Y
- Disallow root login remotely? [Y/n] Y
- Remove test database and access to it? [Y/n] Y
- Reload privilege tables now? [Y/n] Y
其中設置 root 密碼根據情況而來吧,可以修改也可以不修改。
[0x7]設置默認字符集
一般都是設置為utf8,MySQL 的配置文件路徑是/etc/my.cnf,下面就是設置字符集的相關的配置。
? # vim /etc/my.cnf [mysqld] #下面的配置是屬于mysqld的,所以一定要配置在這個下面 #====設置服務端字符集==== #設置數據庫字符集UTF8 character-set-server=utf8 #設置數據庫字符集排序規則,注意要和character-set-server對應 collation-server=utf8_general_ci #設置連接是的字符集 init-connect= 'SET NAMES utf8'# vim /etc/my.cnf [mysqld] #下面的配置是屬于mysqld的,所以一定要配置在這個下面 #====設置服務端字符集==== #設置數據庫字符集UTF8 character-set-server=utf8 #設置數據庫字符集排序規則,注意要和character-set-server對應 collation-server=utf8_general_ci #設置連接是的字符集 init-connect= 'SET NAMES utf8'
保存配置文件,然后重啟 MySQL(systemctl restart mysqld),然后登錄 MySQL,查看現在的字符集。
? [root@virtual ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.16 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> show variables like '%character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.10 sec) mysql>[root@virtual ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.16 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> show variables like '%character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.10 sec) mysql>
[0x8]修改 MySQL 數據目錄
遷移數據庫目錄 MySQL 數據庫默認路徑/var/lib/mysql,實際工作中,常常需要定制數據庫路徑,比如/data/mysql,或者/opt/mysql,一般是單獨的數據盤或者分區,這樣有利于性能調優和保護數據安全,同時也方便進行維護。
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
[mysqld] #下面是系統默認的數據目錄位置 #datadir=/var/lib/mysql #下面這個是修改后的數據目錄位置 datadir=/data/mysql #socket=/var/lib/mysql/mysql.sock socket=/data/mysql/mysql.sock
這個時候如果執行重啟命令,會提示錯誤。
? [root@virtual data]# systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [root@virtual data]#[root@virtual data]# systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [root@virtual data]#
查看錯誤日志,看到其中有這樣的日志2016-11-24T14:01:36.732839Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.突然明白沒有關閉SELinux服務,所以如果按照這個筆記來的話,則不會出現這個問題啦。關閉SELinux然后重啟服務器,就可以正常啟動 MySQL 服務了。
[0x9]結束
至此 MySQL 的安裝和簡單優化操作完成了,總體來看,MySQL 的安裝比較簡單,繁瑣的地方還是在配置,如果想要優化的更好的話,那還有一坨事情等著呢,不過這樣已經滿足一般需求了。
?
作者:mzlion
鏈接:https://hacpai.com/article/1479965479377
來源:黑客派
協議:CC BY-SA 4.0 https://creativecommons.org/licenses/by-sa/4.0/
總結
以上是生活随笔為你收集整理的CentOS7 安装 MySQL 和简单优化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql通过拷贝数据文件的方式进行数据
- 下一篇: mysql inner join