目录
一、准备安装环境
二、初始化mysql
三、配置安全选项
四、同一主机配置其他实例
五、更多mysql安装卸载参考
首页 数据库 mysql教程 基于 Linux 安装glibc版mysql 5.7.12

基于 Linux 安装glibc版mysql 5.7.12

Feb 13, 2017 am 10:43 AM
glibc linux mysql


对于mysql的数据库的安装,我们有很多种选择来完成。而最为常用的为二进制安装以及源码安装。二进制安装方式中,包括rpm版本以及glibc版本。rpm版本就是在特定linux版本下编译的,如果你的linux版本匹配,就可以安装,如针对RedHat6或者RedHat7编译好的rpm包,下载对应的安装即可。还有另外一种二进制安装包为基于特定的glibc版本编译的,本文主要描述基于glibc方式安装mysql。

一、准备安装环境

###准备安装介质下载地址:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz ###或者使用wget方式直接下载对应的版本
# wget http://www.php.cn/# mkdir -pv /u01/app# mkdir -pv /u01/soft# mkdir -pv /u02/mysqldata# cd /u01/soft# wget http://www.php.cn/ 
# tar -xf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz# ln -sv /u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64 /u01/app/mysql`/u01/app/mysql' -> `
/u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64'###下面添加mysql用户# useradd -r mysql -s /sbin/nologin# chown -R mysql:mysql /u01/app/mysql
# chown -R mysql:mysql /u02/mysqldata
登录后复制
登录后复制

二、初始化mysql

###使用以下的方式来初始化# cd /u01/app/mysql/bin# ./mysqld --initialize --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql 
--explicit_defaults_for_timestamp2016-06-28T02:18:23.437852Z 0 [Warning] InnoDB: New log files created, LSN=457902016-06-28T02:18:23.718104Z 0 
[Warning] InnoDB: Creating foreign key constraint system tables.2016-06-28T02:18:23.866501Z 0 [Warning] No existing UUID has been found, 
so we assume that this is the first time that this
     server has been started. Generating a new UUID: 9731b834-3cd6-11e6-8654-fcaa14e34b30.2016-06-28T02:18:23.896540Z 0 
     [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2016-06-28T02:18:23.898416Z 
     1 [Note] A temporary password is generated for root@localhost: )%%D0pr,mU.Y# ls /u02/mysqldata/auto.cnf    client-cert.pem  
     ibdata1      performance_schema  sys
ca-key.pem  client-key.pem   ib_logfile0  server-cert.pem
ca.pem      client-req.pem   ib_logfile1  server-key.pem
ca-req.pem  ib_buffer_pool   mysql        server-req.pem###从上面的结果可以看出 mysql 5.7多出了证书相关文件,安全较5.6有较大提升
###mysql_install_db方式初始化数据已经被废弃# ./mysql_install_db --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql2016-06-28 10:04:56 
[WARNING] mysql_install_db is deprecated. 
Please consider switching to mysqld --initialize2016-06-28 10:05:15 [WARNING] The bootstrap log isn't empty:2016-06-28 10:05:15 [WARNING] 
2016-06-28T02:04:56.688237Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2016-06-28T02:04:56.688654Z 0 
[Warning] Changed limits: max_open_files: 1024 (requested 5000)2016-06-28T02:04:56.688657Z 0 [Warning] Changed 
limits: table_open_cache: 431 (requested 2000)###如上书提示,mysql_install_db方式初始化数据已经被废弃,建议使用mysqld --initialize,同时也给出了参数限制的警告
# cp /u01/app/mysql/support-files/my-default.cnf /etc/my.cnf# cp /u01/app/mysql/support-files/mysql.server /etc/init.d/mysqld# vim /etc/my.cnf [mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir=/u01/app/mysql
datadir=/u02/mysqldata
user=mysql
port=3306# vim /etc/profile.d/mysql.shexport MYSQL_HOME=/u01/app/mysql
export PATH=$PATH:$MYSQL_HOME/bin# source /etc/profile.d/mysql.sh# service mysqld startStarting MySQL.                                            [  OK  ]
登录后复制

三、配置安全选项

###使用初始化时得到的密码配置安全选项
# /u01/app/mysql/bin/mysql_secure_installation -p)%%D0pr,mU.Y
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.

Securing the MySQL server deployment.

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 

VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set 
only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y   ###是否校验密码插件

There are three levels of password validation policy:

LOW    Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2  ###设定密码策略等级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) : 

 ... skipping.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 fortesting, 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 atthe root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y  ###是否关闭root远程登陆功能
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! 

###以下为安全增强相关的部分参数

mysql> show variables like 'valid%';+--------------------------------------+--------+| Variable_name                   | Value  |
+--------------------------------------+--------+| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | STRONG |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
登录后复制

四、同一主机配置其他实例

###按上面描述的步骤创建其对应的目录及授权后,再执行初始化###使用新的配置文件,如下文本示例使用的为3317# mkdir -pv /u02/mysqldata3317# chown -R mysql:mysql 
/u02/mysqldata 3317# grep -v ^# /etc/my3317.cnf[mysqld]
basedir=/u01/app/mysql
datadir=/u02/mysqldata3317
user=mysql
port=3317socket=/tmp/mysql3317.sock# cd /u01/app/mysql/bin# ./mysqld --defaults-file=/etc/my3317.cnf --initialize --user=mysql 
--explicit_defaults_for_timestamp# 2016-06-30T08:32:52.497519Z 0 [Warning] InnoDB: New log files created, LSN=457902016-06-30T08:32:52.852457Z 0 
[Warning] InnoDB: Creating foreign key constraint system tables.2016-06-30T08:32:53.042621Z 0 [Warning] No existing UUID has been found, 
so we assume that this is the first time that this server has been started.
   Generating a new UUID: 3cb1686d-3e9d-11e6-a71f-fcaa14e34b30.2016-06-30T08:32:53.081210Z 0 [Warning] Gtid table is not ready to be used. 
Table 'mysql.gtid_executed' cannot be opened.2016-06-30T08:32:53.082538Z 1 [Note] A temporary password is generated for root@localhost: :8
#l!MCYoCNY### Author : Leshami### Blog   : http://www.php.cn/# mysqld_safe --defaults-file=/etc/my3317.cnf &[1] 58252016-06-30T08:11:49.468176Z 
mysqld_safe Logging to '/u02/mysqldata3317/ydq4.err'.2016-06-30T08:11:49.480379Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information###如果执行mysqld_safe出现上述错误,可以创建软链。
这个地方有问题,对于安装在非缺省目录时出现了这个问题。# mkdir -pv /usr/local/mysql/bin/# ln -sv /u01/app/mysql/bin/mysqld /usr/local/mysql/bin/mysqld
      "/usr/local/mysql/bin/mysqld" -> "/u01/app/mysql/bin/mysqld"# ./mysqld_safe --defaults-file=/etc/my3317.cnf &[1] 82872016-06-30T08:38:38.455961Z
       mysqld_safe Logging to '/u02/mysqldata3317/ydq4.err'.2016-06-30T08:38:38.471542Z mysqld_safe Starting mysqld daemon with databases from 
       /u02/mysqldata3317###配置安全选项# /u01/app/mysql/bin/mysql_secure_installation -P3317 -S /tmp/mysql3317.sock -p
登录后复制

五、更多mysql安装卸载参考


Linux 5 下安装MySQL 5.6(RPM方式)
Linux 下卸载MySQL 5
Linux下基于源码方式安装MySQL 5.6
Linux 下MySQL源码安装完整版
MySQL 源码scr.rpm安装的一点注意事项

对于mysql的数据库的安装,我们有很多种选择来完成。而最为常用的为二进制安装以及源码安装。二进制安装方式中,包括rpm版本以及glibc版本。rpm版本就是在特定linux版本下编译的,如果你的linux版本匹配,就可以安装,如针对RedHat6或者RedHat7编译好的rpm包,下载对应的安装即可。还有另外一种二进制安装包为基于特定的glibc版本编译的,本文主要描述基于glibc方式安装mysql。

一、准备安装环境

###准备安装介质下载地址:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz ###或者使用wget方式直接下载对应的版本
# wget http://www.php.cn/# mkdir -pv /u01/app# mkdir -pv /u01/soft# mkdir -pv /u02/mysqldata# cd /u01/soft# wget http://www.php.cn/ 
# tar -xf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz# ln -sv /u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64 /u01/app/mysql`/u01/app/mysql' -> `
/u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64'###下面添加mysql用户# useradd -r mysql -s /sbin/nologin# chown -R mysql:mysql /u01/app/mysql
# chown -R mysql:mysql /u02/mysqldata
登录后复制
登录后复制

二、初始化mysql

###使用以下的方式来初始化# cd /u01/app/mysql/bin# ./mysqld --initialize --basedir=/u01/app/mysql --datadir=/u02/mysqldata 
--user=mysql --explicit_defaults_for_timestamp2016-06-28T02:18:23.437852Z 0 [Warning] InnoDB: New log files created,LSN=457902016-06-28T02:18:23.718104Z 0 
[Warning] InnoDB: Creating foreign key constraint system tables.2016-06-28T02:18:23.866501Z 0 [Warning] 
No existing UUID has been found, so we assume that this is 
the first time that this
     server has been started. Generating a new UUID: 9731b834-3cd6-11e6-8654-fcaa14e34b30.2016-06-28T02:18:23.896540Z 0 
     [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2016-06-28T02:18:23.898416Z 1 [Note] A 
     temporary password is generated for root@localhost: )%%D0pr,mU.Y# ls /u02/mysqldata/auto.cnf client-cert.pem ibdata1 performance_schema sys
ca-key.pem  client-key.pem   ib_logfile0  server-cert.pem
ca.pem      client-req.pem   ib_logfile1  server-key.pem
ca-req.pem  ib_buffer_pool   mysql        server-req.pem###从上面的结果可以看出 mysql 5.7多出了证书相关文件,安全较5.6有较大提升
###mysql_install_db方式初始化数据已经被废弃# ./mysql_install_db --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql2016-06-28 10:04:56 [WARNING] 
mysql_install_db is deprecated. 
Please consider switching to mysqld --initialize2016-06-28 10:05:15 [WARNING] The bootstrap log isn't empty:2016-06-28 10:05:15 [WARNING] 
2016-06-28T02:04:56.688237Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2016-06-28T02:04:56.688654Z 0 [Warning] 
Changed limits: max_open_files: 1024 (requested 5000)2016-06-28T02:04:56.688657Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
###如上书提示,mysql_install_db方式初始化数据已经被废弃,建议使用mysqld --initialize,同时也给出了参数限制的警告
# cp /u01/app/mysql/support-files/my-default.cnf /etc/my.cnf# cp /u01/app/mysql/support-files/mysql.server /etc/init.d/mysqld# vim /etc/my.cnf [mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir=/u01/app/mysql
datadir=/u02/mysqldata
user=mysql
port=3306# vim /etc/profile.d/mysql.shexport MYSQL_HOME=/u01/app/mysql
export PATH=$PATH:$MYSQL_HOME/bin# source /etc/profile.d/mysql.sh# service mysqld startStarting MySQL.                                        
    [  OK  ]
登录后复制

三、配置安全选项

###使用初始化时得到的密码配置安全选项
# /u01/app/mysql/bin/mysql_secure_installation -p)%%D0pr,mU.Y
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.

Securing the MySQL server deployment.

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 

VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set 
only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y   ###是否校验密码插件

There are three levels of password validation policy:

LOW    Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2  ###设定密码策略等级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) : 

 ... skipping.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 fortesting, 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 atthe root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y  ###是否关闭root远程登陆功能
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! 

###以下为安全增强相关的部分参数

mysql> show variables like 'valid%';+--------------------------------------+--------+| Variable_name                        | Value  |
+--------------------------------------+--------+| validate_password_dictionary_file    |        |
| validate_password_length             | 8      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | STRONG |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+
登录后复制

四、同一主机配置其他实例

###按上面描述的步骤创建其对应的目录及授权后,再执行初始化###使用新的配置文件,如下文本示例使用的为3317# mkdir -pv /u02/mysqldata3317
# chown -R mysql:mysql /u02/mysqldata 3317# grep -v ^# /etc/my3317.cnf[mysqld]
basedir=/u01/app/mysql
datadir=/u02/mysqldata3317
user=mysql
port=3317socket=/tmp/mysql3317.sock# cd /u01/app/mysql/bin# ./mysqld --defaults-file=/etc/my3317.cnf 
--initialize --user=mysql --explicit_defaults_for_timestamp
# 2016-06-30T08:32:52.497519Z 0 [Warning] InnoDB: New log files created, LSN=457902016-06-30T08:32:52.852457Z 0 
[Warning] InnoDB: Creating foreign key 
constraint system tables.2016-06-30T08:32:53.042621Z 0 [Warning] No existing UUID has been found, 
so we assume that this is the first time that this server has been started.
   Generating a new UUID: 3cb1686d-3e9d-11e6-a71f-fcaa14e34b30.2016-06-30T08:32:53.081210Z 0 [Warning] Gtid table is not ready to be used. 
Table 'mysql.gtid_executed' cannot be opened.2016-06-30T08:32:53.082538Z 1 [Note] A temporary password is generated for root@localhost: :8
#l!MCYoCNY### Author : Leshami### Blog   : http://www.php.cn/# mysqld_safe --defaults-file=/etc/my3317.cnf &[1] 58252016-06-30T08:11:49.468176Z 

mysqld_safe Logging to '/u02/mysqldata3317/ydq4.err'.2016-06-30T08:11:49.480379Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information###如果执行mysqld_safe出现上述错误,可以创建软链。这个地方有问题,
对于安装在非缺省目录时出现了这个问题。# mkdir -pv /usr/local/mysql/bin/# ln -sv /u01/app/mysql/bin/mysqld /usr/local/mysql/bin/mysqld      
"/usr/local/mysql/bin/mysqld" -> "/u01/app/mysql/bin/mysqld"# ./mysqld_safe --defaults-file=/etc/my3317.cnf &[1] 82872016-06-30T08:38:38.455961Z 
mysqld_safe Logging to '/u02/mysqldata3317/ydq4.err'.2016-06-30T08:38:38.471542Z mysqld_safe Starting mysqld daemon with databases from /u02/mysqldata3317
###配置安全选项# /u01/app/mysql/bin/mysql_secure_installation -P3317 -S /tmp/mysql3317.sock -p
登录后复制

五、更多mysql安装卸载参考

Linux 5 下安装MySQL 5.6(RPM方式)
Linux 下卸载MySQL 5
Linux下基于源码方式安装MySQL 5.6
Linux 下MySQL源码安装完整版
MySQL 源码scr.rpm安装的一点注意事项

以上就是的内容,更多相关内容请关注PHP中文网(www.php.cn)!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

MySQL的角色:Web应用程序中的数据库 MySQL的角色:Web应用程序中的数据库 Apr 17, 2025 am 12:23 AM

MySQL在Web应用中的主要作用是存储和管理数据。1.MySQL高效处理用户信息、产品目录和交易记录等数据。2.通过SQL查询,开发者能从数据库提取信息生成动态内容。3.MySQL基于客户端-服务器模型工作,确保查询速度可接受。

laravel入门实例 laravel入门实例 Apr 18, 2025 pm 12:45 PM

Laravel 是一款 PHP 框架,用于轻松构建 Web 应用程序。它提供一系列强大的功能,包括:安装: 使用 Composer 全局安装 Laravel CLI,并在项目目录中创建应用程序。路由: 在 routes/web.php 中定义 URL 和处理函数之间的关系。视图: 在 resources/views 中创建视图以呈现应用程序的界面。数据库集成: 提供与 MySQL 等数据库的开箱即用集成,并使用迁移来创建和修改表。模型和控制器: 模型表示数据库实体,控制器处理 HTTP 请求。

解决数据库连接问题:使用minii/db库的实际案例 解决数据库连接问题:使用minii/db库的实际案例 Apr 18, 2025 am 07:09 AM

在开发一个小型应用时,我遇到了一个棘手的问题:需要快速集成一个轻量级的数据库操作库。尝试了多个库后,我发现它们要么功能过多,要么兼容性不佳。最终,我找到了minii/db,这是一个基于Yii2的简化版本,完美地解决了我的问题。

notepad怎么运行java代码 notepad怎么运行java代码 Apr 16, 2025 pm 07:39 PM

虽然 Notepad 无法直接运行 Java 代码,但可以通过借助其他工具实现:使用命令行编译器 (javac) 编译代码,生成字节码文件 (filename.class)。使用 Java 解释器 (java) 解释字节码,执行代码并输出结果。

git怎么查看仓库地址 git怎么查看仓库地址 Apr 17, 2025 pm 01:54 PM

要查看 Git 仓库地址,请执行以下步骤:1. 打开命令行并导航到仓库目录;2. 运行 "git remote -v" 命令;3. 查看输出中的仓库名称及其相应的地址。

laravel安装代码 laravel安装代码 Apr 18, 2025 pm 12:30 PM

要安装 Laravel,需依序进行以下步骤:安装 Composer(适用于 macOS/Linux 和 Windows)安装 Laravel 安装器创建新项目启动服务访问应用程序(网址:http://127.0.0.1:8000)设置数据库连接(如果需要)

sublime怎么设置快捷键 sublime怎么设置快捷键 Apr 16, 2025 am 09:15 AM

要设置 Sublime Text 的快捷键,请遵循以下步骤:打开快捷键设置文件 Key Bindings - User。使用 { "keys": ["按键组合"], "command": "命令" } 的格式添加快捷键设置。保存更改。重新加载快捷键设置以使更改生效。

laravel框架安装方法 laravel框架安装方法 Apr 18, 2025 pm 12:54 PM

文章摘要:本文提供了详细分步说明,指导读者如何轻松安装 Laravel 框架。Laravel 是一个功能强大的 PHP 框架,它 упростил 和加快了 web 应用程序的开发过程。本教程涵盖了从系统要求到配置数据库和设置路由等各个方面的安装过程。通过遵循这些步骤,读者可以快速高效地为他们的 Laravel 项目打下坚实的基础。

See all articles