由于安装的mysql8.0和其他服务器的数据库(版本5.1.30)由于版本差异过大,无法通信,因此需要安装一个中间版本5.6,但是它的安装过程和mysql8.0安装略有不同。

解压文件

// 解压文件生成两个xz格式的压缩文件

$ tar -xzvf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz

// 为了方便查找,改个名字

mv mysql-5.6.42-linux-glibc2.12-x86_64 mysql5

// 为了使用mysql快速初始化,链接到指定目录

ln -s /home/work/lnmp/mysql5/ /usr/local/mysql

环境配置

我们需要专门的mysql进程启动用户和权限管理:

// 创建mysql系统用户和用户组

useradd -r mysql

// 给予安装目录mysql权限

chown mysql:mysql -R mysql5

配置自己的mysql配置文件,因为我有多个Mysql库,我手动指定很多参数:

[client]

socket=/home/work/lnmp/mysql5/tmp/mysql.sock

default-character-set=utf8

[mysql]

basedir=/home/work/lnmp/mysql5/

datadir=/home/work/lnmp/mysql5/data/

socket=/home/work/lnmp/mysql5/tmp/mysql.sock

port=3306

user=mysql

# 指定日志时间为系统时间

log_timestamps=SYSTEM

log-error=/home/work/lnmp/mysql5/log/mysql.err

[mysqld]

basedir=/home/work/lnmp/mysql5/

datadir=/home/work/lnmp/mysql5/data/

socket=/home/work/lnmp/mysql5/tmp/mysql.sock

port=3306

user=mysql

log_timestamps=SYSTEM

collation-server = utf8_unicode_ci

character-set-server = utf8

[mysqld_safe]

log-error=/home/work/lnmp/mysql5/log/mysqld_safe.err

pid-file=/home/work/lnmp/mysql5/tmp/mysqld.pid

socket=/home/work/lnmp/mysql5/tmp/mysql.sock

[mysql.server]

basedir=/home/work/lnmp/mysql5

socket=/home/work/lnmp/mysql5/tmp/mysql.sock

[mysqladmin]

socket=/home/work/lnmp/mysql5/tmp/mysql.sock

这个里面我指定了错误日志的路径,在接下来的操作中,如果出现错误,除了查看终端显示的错误,还要记得去错误日志里查看详细的信息。

因为我指定了一些文件,所以需要提前创建:

mkdir log

touch log/mysql.err

touch log/mysqld_safe.err

mkdir tmp

mkdir data

cd .. & chown mysql:mysql -R mysql5

数据库初始化

如果我们不初始化,直接使用bin/mysqld_safe启动会报错,因为我们需要初始化mysql环境,具体的操作可以参考官方文档:

$ scripts/mysql_install_db --user=mysql

...

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'

./bin/mysqladmin -u root -h szwg-cdn-ai-predict00.szwg01.baidu.com password 'new-password'

Alternatively you can run:

./bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file ./my.cnf on the system.

Because this file might be in use, it was not replaced,

but was used in bootstrap (unless you used --defaults-file)

and when you later start the server.

The new default config file was created as ./my-new.cnf,

please compare it with your file and take the changes you need.

提示中提示我们已经创建了root的用户,需要修改临时密码,同时初始化成功。也告诉我们怎么启动一个数据库实例。

启动数据库

我们使用mysqld_safe 命令来启动:

$ bin/mysqld_safe

181217 14:55:08 mysqld_safe Logging to '/home/work/lnmp/mysql5/log/mysqld_safe.err'.

181217 14:55:08 mysqld_safe Starting mysqld daemon with databases from /home/work/lnmp/mysql5/data

链接全局命令

此时,我们调用mysql只能用路径/home/work/lnmp/mysql8/bin/mysql或相对路径,需要链接为全局命令:

$ ln -s /home/work/lnmp/mysql8/bin/mysql /usr/bin/

$ ln -s /home/work/lnmp/mysql8/bin/mysql_safe /usr/bin/

打开数据库

数据库进程已经启动,我们可以在新终端正常使用mysql数据库,但是直接使用mysql命令报错:

$ mysql -uroot

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

我查看了官方安装多个数据库的文档,尝试了很多方法,依然没有办法指定mysql命令的默认socket路径(/tmp/mysql.sock)。但是根据mysql.sock的作用的说明,我们指定mysql.sock路径即可:

bin/mysql -S /home/work/lnmp/mysql8/tmp/mysql.sock -h localhost -uroot -p

Enter password:

或者:

ln -s /home/work/lnmp/mysql8/tmp/mysql.sock /tmp/

然后我们再调用mysql命令就不会报错了。

修改初始密码

初始化的时候,命令行文本已经提示我们需要怎样更新root密码,并根据他的指示操作即可,要详细阅读输出的文本:

$ bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current

password for the root user. If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

连接数据库,新密码已经更新。

参考文章

linux安装mysql5.6整套_Linux安装Mysql5.6相关推荐

  1. linux安装mysql5.6整套_Linux下安装MySQL5.6

    环境: 1.操作系统:CentOS release 6.8 (Final) 2.安装版本: mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz 3.下载地址:http: ...

  2. linux mysql 5.7 配置_linux下mysql5.7的安装配置

    mysql官方下载地址: https://dev.mysql.com/downloads/mysql/ 安装步骤: # https://cdn.mysql.com//Downloads/MySQL-5 ...

  3. linux查看 mysql 登陆 失败_Linux安装完mysql后提示错误无法登陆mysql怎么办?

    mysql是数据库,用于管理系统的数据,使用非常广泛,Linux系统操作中,在安装完mysql后提示错误,导致用户无法登陆,遇到这种情况该怎么办呢?下面小编就给大家介绍下Linux无法登陆mysql的 ...

  4. linux dpkg未找到命令_Linux安装软件时90%的人会遇到这个报错,如何解决?

    提示 Could not get lock /var/lib/dpkg/lock 报错? 有些小伙伴在使用 apt 包管理器更新或安装软件时,可能会遇到过诸如以下的错误提示: E: Could not ...

  5. linux tomcat连接mysql步骤_Linux安装JDK 、TOMCAT 、MYSQL 步骤

    安装JDK的步骤: 1. 上传文件安装到root目录中 2. 使用 tar -xvf 命令 解压安装到文件的当前目录 3. 剪切解压后的安装包到 /usr/local中并重命名为jdk 4. 进入到/ ...

  6. linux设置nexus开机自启动_linux安装nexus(支持jdk1.7)并设置开机启动

    版本:nexus-2.6.4-02-bundle 这个版本jdk需要1.7或以上 注:nexus 2.6版本之后不再支持jdk1.6 nexus 2.5.x nexus最后一个支持jdk1.6版本的 ...

  7. linux下安装python3报错_linux安装python3

    1.下载python# wget //www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz 2.解压.编译安装(依次执行以下5条命令)# tar -zxvf ...

  8. crt安装mysql安装包_Linux安装MySQL步骤

    1. 通过secureCRT工具连接Linux系统 2. 上传 mysql 的安装包 alt + p -------> put d:/setup/mysql-5.7.27-1.el7.x86_6 ...

  9. linux的mysql本地yum安装_Linux下MySQL5.7.18 yum方式从卸载到安装过程图解

    折腾了大半天,看了想,想了看,总算是弄清楚yum安装的过程了,之前写过二进制包安装的,这里用yum安装,环境都是一样的,Centos7.2+MySQL5.7.18. 每一步都参考了不少文章,后面会一一 ...

最新文章

  1. saltstack使用指南----常用执行模块
  2. loadrunner中创建唯一随机数
  3. 多个视频切换时,只改变SourceFilter,不改变Filter Graph中其他Filter的C#实现
  4. centos7安装tomcat8.5.46版本
  5. ubuntu的apache配置https
  6. apache php日志配置,HTML_初学:apache与php基本配置,1、APACHE的日志主要分为“ - phpStudy...
  7. 关于open***的实验总结
  8. Cerberus 银行木马开发团队解散,源代码5万美元起拍
  9. 去除input的自动填充色
  10. 【图像隐写】基于matlab DWT数字水印多种攻击效果对比【含Matlab源码 1134期】
  11. 简述ip地址的abc类如何划分_IP地址的ABC类划分
  12. 阿里fastjson 对象转JSON
  13. html5读取umd,教程:使用umd、commonjs和es三种模式制作自己的React 组件(库)
  14. SQL Server 修改字段名
  15. 新建网站常用的50个网站推广方法
  16. 线性代数 06 克莱默法则
  17. Alpha版本——展示博客【第二组】
  18. Span 有多强大?玩转各种文字特效
  19. 74HC165并转串级联芯片学习记录
  20. 3月18日云栖精选夜读 | 开发者必看!探秘阿里云Hi购季开发者分会场:海量学习资源0元起!... 1

热门文章

  1. MySQL精选 | 枚举类型ENUM的DDL变更测试
  2. 【感恩,回馈,展望】2018 ACOUG 年会盛大来袭!
  3. 毫秒级从百亿大表任意维度筛选数据,是怎么做到的…
  4. 带你认识9种常用卷积神经网络
  5. 经典永流传,华为云媒体 AI 让老电影焕发新生
  6. 【读一本书】《昇腾AI处理器架构与编程》--神经网络基础知识(2)
  7. 【Python成长之路】Python爬虫 --requests库爬取网站乱码(\xe4\xb8\xb0\xe5\xa)的解决方法【华为云分享】
  8. 【nodejs原理源码赏析(2)】KOA中间件的基本运作原理
  9. git提取和拉取区别_每天一Git之起步 - 关于版本控制
  10. mysql 匹配所有记录_如何记录mysql中所有的查询