array(2) { ["docs"]=> array(10) { [0]=> array(10) { ["id"]=> string(3) "428" ["text"]=> string(77) "Visual Studio 2017 单独启动MSDN帮助(Microsoft Help Viewer)的方法" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(8) "DonetRen" ["tagsname"]=> string(55) "Visual Studio 2017|MSDN帮助|C#程序|.NET|Help Viewer" ["tagsid"]=> string(23) "[401,402,403,"300",404]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400964" ["_id"]=> string(3) "428" } [1]=> array(10) { ["id"]=> string(3) "427" ["text"]=> string(42) "npm -v;报错 cannot find module "wrapp"" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "zzty" ["tagsname"]=> string(50) "node.js|npm|cannot find module "wrapp“|node" ["tagsid"]=> string(19) "[398,"239",399,400]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400760" ["_id"]=> string(3) "427" } [2]=> array(10) { ["id"]=> string(3) "426" ["text"]=> string(54) "说说css中pt、px、em、rem都扮演了什么角色" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(12) "zhengqiaoyin" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400640" ["_id"]=> string(3) "426" } [3]=> array(10) { ["id"]=> string(3) "425" ["text"]=> string(83) "深入学习JS执行--创建执行上下文(变量对象,作用域链,this)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "Ry-yuan" ["tagsname"]=> string(33) "Javascript|Javascript执行过程" ["tagsid"]=> string(13) "["169","191"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511399901" ["_id"]=> string(3) "425" } [4]=> array(10) { ["id"]=> string(3) "424" ["text"]=> string(30) "C# 排序技术研究与对比" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "vveiliang" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(8) ".Net Dev" ["catesid"]=> string(5) "[199]" ["createtime"]=> string(10) "1511399150" ["_id"]=> string(3) "424" } [5]=> array(10) { ["id"]=> string(3) "423" ["text"]=> string(72) "【算法】小白的算法笔记:快速排序算法的编码和优化" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "penghuwan" ["tagsname"]=> string(6) "算法" ["tagsid"]=> string(7) "["344"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511398109" ["_id"]=> string(3) "423" } [6]=> array(10) { ["id"]=> string(3) "422" ["text"]=> string(64) "JavaScript数据可视化编程学习(二)Flotr2,雷达图" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "chengxs" ["tagsname"]=> string(28) "数据可视化|前端学习" ["tagsid"]=> string(9) "[396,397]" ["catesname"]=> string(18) "前端基本知识" ["catesid"]=> string(5) "[198]" ["createtime"]=> string(10) "1511397800" ["_id"]=> string(3) "422" } [7]=> array(10) { ["id"]=> string(3) "421" ["text"]=> string(36) "C#表达式目录树(Expression)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "wwym" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(4) ".NET" ["catesid"]=> string(7) "["119"]" ["createtime"]=> string(10) "1511397474" ["_id"]=> string(3) "421" } [8]=> array(10) { ["id"]=> string(3) "420" ["text"]=> string(47) "数据结构 队列_队列实例:事件处理" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "idreamo" ["tagsname"]=> string(40) "C语言|数据结构|队列|事件处理" ["tagsid"]=> string(23) "["246","247","248",395]" ["catesname"]=> string(12) "数据结构" ["catesid"]=> string(7) "["133"]" ["createtime"]=> string(10) "1511397279" ["_id"]=> string(3) "420" } [9]=> array(10) { ["id"]=> string(3) "419" ["text"]=> string(47) "久等了,博客园官方Android客户端发布" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(3) "cmt" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511396549" ["_id"]=> string(3) "419" } } ["count"]=> int(200) } 222 【Linux】数据库系列之MySQL5.7x的安装与初始化 - 爱码网

---恢复内容开始---

          上次装Oracle出的问题真是太多太多了,MySQL会简单许多,这次就来分析下MySQL在Linux上的安装与初始化。同样系统是centos7.x

MySQL的安装方式很多。我主要用了2种方式:源码包方式(安装内容模块可以自定义,稳定性高,但是比较费时间)二进制包安装方式(比较方便,初始化安装后就可以用)

一、二进制包方式

1、登录MySQL官网:https://www.mysql.com/downloads/

【Linux】数据库系列之MySQL5.7x的安装与初始化

2、选择需要的安装版本(社区版)

【Linux】数据库系列之MySQL5.7x的安装与初始化

【Linux】数据库系列之MySQL5.7x的安装与初始化

【Linux】数据库系列之MySQL5.7x的安装与初始化

3、安装

上传下载的MySQL5.7x到centos7x虚拟机内,或者wget下载。

解压:

[[email protected] opt]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
[[email protected] opt]# mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
[[email protected] opt]# cd /usr/local/mysql/
[[email protected] mysql]# useradd mysql
[[email protected] mysql]# mkdir data
[[email protected] mysql]# chown -R mysql:mysql /usr/local/mysql/

5.7.x之后的版本初始化数据库不再使用mysql_install_db,而是使用: bin/mysqld --initialize.

[[email protected] bin]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-02-21 17:05:27 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-02-21 17:05:31 [WARNING] The bootstrap log isn't empty:
2019-02-21 17:05:31 [WARNING] 2019-02-21T09:05:28.203493Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

[[email protected] bin]# 

使用mysqld --initialize:

[[email protected] bin]# ./mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-02-21T09:07:47.784915Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-02-21T09:07:47.786735Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-02-21T09:07:47.786768Z 0 [ERROR] Aborting

[[email protected] bin]# rm -rf /usr/local/mysql/data/*
[[email protected] bin]# ./mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-02-21T09:09:32.773141Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-02-21T09:09:34.064508Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-02-21T09:09:34.252282Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-02-21T09:09:34.320052Z 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: 67cc2fdb-35b8-11e9-a738-000c29186a7c.
2019-02-21T09:09:34.321735Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-02-21T09:09:34.330050Z 1 [Note] A temporary password is generated for [email protected]: >aHMp/_V3(Aq
[[email protected] bin]#

ps:注意保存最后面的密码。

创建配置文件:

[[email protected] bin]# vim /etc/my.cnf

发现存在my.cnf文件看来系统自带了mariadb,卸载它。

[[email protected] bin]# rpm -qa |grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[[email protected] bin]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
[[email protected] bin]# rpm -qa |grep mariadb

 现在已经卸载了系统自带的mariadb,继续创建my.cnf

编辑my.cnf:

【Linux】数据库系列之MySQL5.7x的安装与初始化

[[email protected] support-files]# cp ./mysql.server /etc/in
init.d/  inittab  inputrc  
[[email protected] support-files]# cp ./mysql.server /etc/init.d/mysqld
[[email protected] support-files]# chmod +x /etc/init.d/mysqld

设置开机自启动:

[[email protected] support-files]# chkconfig --add mysqld
[[email protected] support-files]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld             0:关    1:关    2:开    3:开    4:开    5:开    6:关
netconsole         0:关    1:关    2:关    3:关    4:关    5:关    6:关
network            0:关    1:关    2:开    3:开    4:开    5:开    6:关

将MySQL服务添加到系统服务以便设置开机自启:(2、3、4、5级别启动时开启MySQL)

redhalt7系统使用了systemctl 不过保留了原来的service 仍然可以使用。

启动MySQL:

[[email protected] support-files]# service mysqld start
Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/centos7.pid).

出现错误:不能更新进程id文件:

解决重新进行初始化:

在初始化前先删除data里的全部文件

[[email protected] bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --pid-file=/usr/local/mysql/data/mysql.pid 
2019-02-22T01:02:07.626070Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-02-22T01:02:08.873600Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-02-22T01:02:09.114675Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-02-22T01:02:09.207208Z 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: 7ac3daf9-363d-11e9-b3db-000c29186a7c.
2019-02-22T01:02:09.209157Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-02-22T01:02:09.213326Z 1 [Note] A temporary password is generated for [email protected]: s-jwb*inb5L4
[[email protected] bin]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/centos7.err'.
 SUCCESS! 
[[email protected] bin]# ps -ef |grep mysql
root       2919      1  0 09:02 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/centos7.pid
mysql      3121   2919  2 09:02 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=centos7.err --pid-file=/usr/local/mysql/data/centos7.pid --socket=/usr/local/mysql/data/mysql.sock --port=3306
root       3151   2080  0 09:02 pts/0    00:00:00 grep --color=auto mysql
[[email protected] bin]# 

登录MySQL:

在/usr/local/mysql/bin目录下执行:

[[email protected] bin]# ./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.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 

这里因为在/etc/my.cnf里加入了skip-grant-tables选项因此不需要输入密码就可以登录,没有设置该参数,输入初始化产生的初始密码就可以了。(为了安全在更改密码后该参数需要删除)

更改密码;

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> update user set authentication_string=password('123456') where user='root'
    -> ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

第一次密码登录root用户后必须执行:

mysql> alter user 'root'@'localhost' identified by 'xxx' PASSWORD EXPIRE NEVER account unlock;    #原本密码有效期为360天需要取消这个限制。

mysql> flush privileges;

重新登录mysql:

更改my.cnf

【Linux】数据库系列之MySQL5.7x的安装与初始化

删除红框部分,保存!

重启mysql

[[email protected] bin]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

登录后注意修改root密码期限。

登录MySQL并创建一个能够远程登录的用户:

使用sqlyog验证:

【Linux】数据库系列之MySQL5.7x的安装与初始化

二、使用源码包方式安装MySQL5.7x

1.安装编译工具和所需要的依赖库:

yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 flex libaio-devel

发现:

【Linux】数据库系列之MySQL5.7x的安装与初始化

手动安装它:

 一共安装4个文件:

【Linux】数据库系列之MySQL5.7x的安装与初始化

先安装libmcrypt 在安装devel。mhash也是同样

安装cmake编译工具:

官网:http://www.cmake.org

下载;

wget http://www.cmake.org/files/v3.1/cmake-3.1.1.tar.gz

 安装:

tar zxvf cmake-3.1.1.tar.gz
cd cmake-3.1.1
./bootstrap
make && make install

安装MySQL:

下载:

【Linux】数据库系列之MySQL5.7x的安装与初始化

地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

编译:

[[email protected] opt]# tar -zxvf mysql-boost-5.7.25.tar.gz 
[[email protected] opt]# cd ./mysql-5.7.25/

[[email protected] mysql-5.7.25]#

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/opt/mysql-5.7.25/boost \
-DSYSCONFDIR=/etc \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all

可能出现;

报错代码:

CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
解决办法:
1.在/usr/local下创建一个名为boost的文件夹
mkdir -p /usr/local/boost
2.进入这个新创建的文件夹然后下载boost
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
3.解压
tar -xvzf boost_1_59_0.tar.gz
4.重新cmake,后面更改以下参数
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost/ \

安装:

make && make install

【Linux】数据库系列之MySQL5.7x的安装与初始化

这个过程大概持续30min.......

【Linux】数据库系列之MySQL5.7x的安装与初始化

接下来就是数据库的初始化:

初始化方法与二进制包方法一致:这里就不在赘述了。

相关文章: