当前位置: 56net亚洲必嬴 > 数据库 > 正文

CentOS 7.2 Yum编写翻译安装MySQL 5.6

时间:2019-10-24 18:29来源:数据库
生机勃勃、MySQL数据库的合法兰西网球国际竞赛址: https://www.oracle.com/ http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html       //不一致版本的装置文书档案和下载能够在这里间找 本文介

生机勃勃、MySQL数据库的合法兰西网球国际竞赛址:

  • https://www.oracle.com/
  • http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html
  •        //不一致版本的装置文书档案和下载能够在这里间找

本文介绍mysql各个安装情势(rpm/glibc通用二进制/源码编写翻译)甚至多实例配置的方式,没什么技巧,算是大器晚成篇方法归总随笔。

本文目录:
1. mysql单实例安装
  1.1 rpm安装mysql
  1.2 通用二进制包安装mysql
    1.2.1 带头化数据库
    1.2.2 安装后的标准化操作
  1.3 编写翻译安装
    1.3.1 编译安装进度
    1.3.2 初始化
    1.3.3 规范化
    1.3.4 cmake编写翻译MySQL时的抉择表达
2. mysql多实例配置
  2.1 mysql多实例配置进程
  2.2 提供sysV服务管理脚本
  2.3 提供systemd服务管理脚本
3. mariadb安装

本文实例为大家寒不择衣CentOS 7.2 Yum安装mysql5.6的艺术,供大家参照他事他说加以考察,具体内容如下

二、MySQL的装置格局:

以下是MySQL常见的三种安装情势:

  • 二进制  rpm   Yum Repository    mysql57-community-release-el7-9.noarch.rpm
  • 二进制  预编译  Generic                        mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
  • 源码包安             Source Code                mysql-5.7.19.tar.gz
  1. 本文的安装意况为centos6.6和centos7.2,但超过半数地点都是centos6.6作为示范示例。
  2. 本文安装MySQL时,它们的运行地方为mysql,数据目录datadir为/mydata/data。
  3. pid文件路线设置为/mydata/data/mysql.pid或/mydata/data/`hostname`.pid。
  4. 是因为mariadb和mysql 5多如牛毛并未太大的不及。因而仅详细显示mysql的装置。最终将轻松提后生可畏提mariadb。

  5. mysql单实例安装

正文介绍mysql种种安装方式(rpm/glibc通用二进制/源码编译)以至多实例配置的措施,没什么本领,算是风姿浪漫篇方法归总小说。

配置CentOS SCLo源

三、Yum的方法安装MySQL:

  • yum安装mysql 5.7 的法虞升卿装情势地址

1、下载安装包

  • *此地址为Mysql 8.0 的安装源当中包罗MySQL 5.7的源,可以在末端步骤修改开放的库房: *

2、 设置安装起来境况

暂时先把防火墙关闭保证实验顺利:
[root@host-131 ~]# systemctl stop firewalld 
[root@host-131 ~]# systemctl disable firewalld.service
临时关闭SELlinux:
[root@host-131 ~]# setenforce 0
永久关闭SELinux:
[root@host-131 ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
查看SELinux状态:
[root@host-131 ~]# getenforce
Disabled

 3、卸载系统自带的数据库(Centos7自带的是maridb)

1.1 rpm包安装mysql

间接yum安装mysql-server就可以。但只顾两点:

(1).centos7上,yum暗许将安装mariadb。
(2).centos6上,yum暗许安装的版本相比老(5.1版),要设置mysql 5.6或mysql 5.7,能够从官方下载,也得以运用以下配置的yum源。

release=`awk  -F "[ .]" '{print $4}' /etc/redhat-release`
cat <<eof>/etc/yum.repos.d/mysql.repo
[mysql56]
name=MySQL
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/$release/$basearch/
enabled=1
gpgcheck=0

[mysql57]
name=MySQL
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/$release/$basearch/
enabled=1
gpgcheck=0
eof

此外,在sohu镜像站点也提供了mysql的依次rpm版本。地址:http://mirrors.sohu.com/mysql/

还需注意,配置了yum源后装置Mysql将应用mysql-community-*安装各mysql相关包,例如mysql-community-server。

设置完结后,运维mysqld。

shell> service mysqld start      # 或 systemctl start mysqld

若是开发银行战败,则恐怕供给开头化MySQL。

shell> mkdir -p /mydata/data
shell> chown -R mysql.mysql /mydata/data
shell> mysql_install_db --datadir=/mydata/data --user=mysql

风流倜傥旦应用mysql_install_db伊始化时提示该命令已经打消(5.7版本恐怕会如此提醒),那么使用下边的一声令下举行初阶化。

# 初始化时,为root@localhost创建一个临时密码存放在mysql.log中
shell> mysqld --initialize --datadir=/mydata/data --user=mysql
# 初始化时,为root@localhost创建一个空密码
shell> mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

最早化后再开发银行,运维成功后连连数据库并修正root@localhost客户的密码,然后退出。

shell> mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> q

假诺前方使用mysqld --initialize起头化数据库,那么将会为"root@localhost"创立多少个密码,那将使得不能间接使用mysql命令连接数据库。可以先从mysql.log中筛选出创设的一时密码,然后再手动更改为"123456"。

shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> q
  1. 本文的设置意况为centos6.6和centos7.2,但超多地点都是centos6.6作为示范示例。
  2. 本文安装MySQL时,它们的运维地点为mysql,数据目录datadir为/mydata/data。
  3. pid文件路线设置为/mydata/data/mysql.pid或/mydata/data/`hostname`.pid。
  4. 是因为mariadb和mysql 5体系并不曾太大的例外。因而仅详细显示mysql的设置。最终将简单提风流浪漫提mariadb。

  5. mysql单实例安装

[3] 添加 CentOS SCLo Software collections Repository.
[root@linuxprobe~]# yum -y install centos-release-scl-rh centos-release-scl
# set [priority=10]
[root@linuxprobe~]# sed -i -e "s/]$/]npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@linuxprobe~]# sed -i -e "s/]$/]npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# for another way, change to [enabled=0] and use it only when needed
[root@linuxprobe~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
[root@dlp ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

可参考:【MySQL解惑笔记】Centos7下卸载彻底MySQL数据库

卸载maridb:
[root@host-131 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@host-131 ~]# yum -y remove mari*
[root@host-131 ~]# rm -rf /var/lib/mysql/*
[root@host-131 ~]# rpm -qa | grep mariadb
[root@host-131 ~]# 

4、匡正旅馆

[root@host-131 src]# yum rpolist all |grep mysql      //查看所有仓库,并能够看到开启和禁用的仓库
[root@host-131 src]# yum repolist enabled | grep "mysql.*-community.*"  //查看所有开启的仓库,发现现在开启的是MySQL 8.0的,我们需要开启MySQL5.7的仓库
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql80-community/x86_64          MySQL 8.0 Community Server                  17     //k

 开启和关闭不同仓库,官方提供了三种修改方法:

方法一:
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community

方法二:
shell> sudo dnf config-manager --disable mysql57-community
shell> sudo dnf config-manager --enable mysql56-community

方法三:
我们直接修改Yum源文件:
[root@host-131 ~]# cd /etc/yum.repos.d 
[root@host-131 yum.repos.d]# vim mysql-community.repo 
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1                        //修改为1表示开启
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0                        //修改为0表示关闭
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[root@host-131 yum.repos.d]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql57-community/x86_64          MySQL 5.7 Community Server                 267    //可以看到5.7存储仓库已经开启

注意:我们应该在任何时候只启用一个发布系列的子存储库。当启用多个发布系列的子存储库时,Yum将使用最新的系列。
通过运行以下命令并检查其输出(对于Fedora,用dnf替换yum),验证是否启用了正确的子库并禁用了它:
[root@host-131 yum.repos.d]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql57-community/x86_64          MySQL 5.7 Community Server                 267

 5、安装MySQL数据库

[root@host-131 yum.repos.d]# yum -y install mysql-community-server
[root@host-131 ~]# systemctl start mysqld   
[root@host-131 ~]# systemctl enable mysqld   设置开机自启动
[root@host-131 ~]# systemctl status mysqld  查看mysql启动状态

[root@host-131 ~]# ls /var/lib/mysql    (安装后可以看到初始化的数据库)
auto.cnf    client-cert.pem  ibdata1      ibtmp1      mysql.sock.lock     public_key.pem   sys
ca-key.pem  client-key.pem   ib_logfile0  mysql   performance_schema  server-cert.pem
ca.pem      ib_buffer_pool   ib_logfile1  mysql.sock  private_key.pem     server-key.pem

6、第贰次登陆数据库,并设置开首化密码

[root@host-131 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
发现是禁止访问的

在服务器的初始启动时,由于服务器的数据目录为空:服务器初始化。SSL证书和密钥文件是在数据目录中生成的。
安装并启用了validate_password。
一个超级用户帐户'root'@'localhost被创建。
超级用户的密码被设置并存储在错误日志文件中。要显示它,请使用以下命令:

MySQL5.5之前版本安装后可以直接登录
MySQL5.5自动生成的密码是空的
MySQL5.6是将密码放在root下的
MySQL5.7是将密码放在:
[root@host-131 ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-30T06:34:56.956716Z 1 [Note] A temporary password is generated for root@localhost: xt8S3rWXOL/C
[root@host-131 ~]# 
[root@host-131 ~]# mysql -uroot -p"xt8S3rWXOL/C"
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.22
修改密码:
方法一:
[root@host-131 ~]# mysqladmin -uroot -p"xt8S3rWXOL/C" password "Yanglt123."   //密码要满足复杂性要求
[root@host-131 ~]# mysql -uroot -p"Yanglt123."

方法二:

[root@host-131 ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-30T06:34:56.956716Z 1 [Note] A temporary password is generated for root@localhost: xt8S3rWXOL/C
[root@host-131 ~]# 
[root@host-131 ~]# mysql -uroot -p"xt8S3rWXOL/C"

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

 到此数据库安装成功:

源码安装可参看随笔:*【Linux运营】LNMP景况安顿*

  

1.2 通用二进制包安装mysql

通用二进制包相当于windows中的便携版软件,解压后有一些配置下就足以平昔运用,不用安装。

mysql通用二进制版官方下载地址:

  • MySQL 5.6通用二进制包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.12-x86_64.tar.gz
  • MySQL 5.7通用二进制包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.12-x86_64.tar.gz

内部文件中的glibc2.12表示的是Linux系统的glibc版本要比2.12新,能够行使ldd --version查阅glibc版本。在CentOS 6上glibc暗许就是2.12的,所以不用操心。

shell> tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
shell> ln -s /usr/local/mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql

1.1 rpm包安装mysql

直接yum安装mysql-server就可以。但注意两点:

(1).centos7上,yum暗中同意将安装mariadb。
(2).centos6上,yum暗中认可安装的本子比较老(5.1版),要安装mysql 5.6或mysql 5.7,能够从官方下载,也得以行使以下配置的yum源。

cat <<eof>/etc/yum.repos.d/mysql.repo
[mysql]
name=MySQL
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
# baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
# baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
# baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
eof

其余,在sohu镜像站点也提供了mysql的次第rpm版本。地址:http://mirrors.sohu.com/mysql/

还需注意,配置了yum源后安装Mysql将利用mysql-community-*安装各mysql相关包,例如mysql-community-server。

设置到位后,运转mysqld。

shell> service mysqld start      # 或 systemctl start mysqld

大器晚成旦开发银行战败,则或许须要初始化MySQL。

shell> mkdir -p /mydata/data
shell> chown -R mysql.mysql /mydata/data
shell> mysql_install_db --datadir=/mydata/data --user=mysql

只要运用mysql_install_db起始化时提示该命令已经打消(5.7本子只怕会如此提醒),那么使用上面的一声令下举办先导化。

# 初始化时,为root@localhost创建一个临时密码存放在mysql.log中
shell> mysqld --initialize --datadir=/mydata/data --user=mysql
# 初始化时,为root@localhost创建一个空密码
shell> mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

起首化后再起步,启动成功后连连数据库并校订root@localhost客户的密码,然后退出。

shell> mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> q

万一前面使用mysqld --initialize初阶化数据库,那么将会为"root@localhost"创造一个密码,那将使得无法直接运用mysql命令连接数据库。能够先从mysql.log中筛选出制造的暂时密码,然后再手动改革为"123456"。

shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> q

yum安装MySQL

1.2.1 开首化数据库

不应用rpm包安装,就须要对mysql实行初阶化以创设一些文本、库和点名一些参数。但在开头化mysql前,要先行做一些操作。

shell> mkdir -p /mydata/data
shell> useradd -r -s /sbin/nologin mysql
shell> chown -R mysql.mysql /usr/local/mysql
shell> chown -R mysql.mysql /mydata/data
shell> cd /usr/local/mysql
shell> scripts/mysql_install_db --datadir=/mydata/data --user=mysql
shell> chown -R root.root /usr/local/mysql

执行mysql_install_db时会在/tmp下创设一时表,所以mysql顾客须求对/tmp有写权限,不然奉行实例最初化脚本时也许会报相仿上边包车型地铁荒诞:
ERROR: 1 Can't create/write to file '/tmp/#sql_7a0e_0.MYI' (Errcode: 13)
那表明未有写权限,所以需求订正/tmp目录的权能:

chmod 1777 /tmp

同样,mysql_install_db开首时后生可畏旦指示已废弃,则接纳如下方法:

bin/mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

初叶化实现后,提供配置文件和劳务运营脚本。

shell> cp -a support-files/mysql.server /etc/init.d/mysqld
shell> cp -a support-files/my-default.cnf /etc/my.cnf  

# 修改my.cnf的datadir
shell> vim /etc/my.cnf 
[mysqld]
datadir=/mydata/data

若是是centos7,则提供如下服务运营脚本(如有供给,修正pid文件路径)。

shell> cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/var/run/mysqld/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Start main service
ExecStart=/usr/local/mysql-5.7.19/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

修改"root@localhost"密码。

shell> mysql
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> q

1.2 通用二进制包安装mysql

通用二进制包也正是windows中的便携版软件,解压后某个配置下就能够直接接收,不用安装。

mysql通用二进制版官方下载地址:

  • MySQL 5.6通用二进制包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.12-x86_64.tar.gz
  • MySQL 5.7通用二进制包下载:
    https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.12-x86_64.tar.gz

中间文件中的glibc2.12表示的是Linux系统的glibc版本要比2.12新,能够利用ldd --version查看glibc版本。在CentOS 6上glibc暗中同意就是2.12的,所以不要顾忌。

shell> tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
shell> ln -s /usr/local/mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
# 安装mysql
[root@linuxprobe~]# yum --enablerepo=centos-sclo-rh -y install rh-mysql56-mysql-server
# 加载环境变量
[root@linuxprobe ~]# scl enable rh-mysql56 bash
[root@linuxprobe ~]# mysql -V 
mysql Ver 14.14 Distrib 5.6.26, for Linux (x86_64) using EditLine wrapper
[root@linuxprobe ~]# which mysql 
/opt/rh/rh-mysql56/root/usr/bin/mysql
# 设置mysql开机自启动
root@linuxprobe ~]# vi /etc/profile.d/rh-mysql56.sh
#!/bin/bash
source /opt/rh/rh-mysql56/enable
export X_SCLS="`scl enable rh-mysql56 'echo $X_SCLS'`"




[4] Enable MySQL 5.6 and Configure initial settings.
[root@linuxprobe ~]# vi /etc/opt/rh/rh-mysql56/my.cnf.d/mysql-server.cnf
# add follows within [mysqld] section
[mysqld]
character-set-server=utf8
[root@linuxprobe ~]# systemctl start rh-mysql56-mysqld
[root@linuxprobe ~]# systemctl enable rh-mysql56-mysqld
[root@linuxprobe ~]# 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
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
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
Remove anonymous users? [Y/n] 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
Disallow root login remotely? [Y/n] 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
Remove test database and access to it? [Y/n] 
 - 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
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!




[root@linuxprobe ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 13
Server version: 5.6.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> select user,host,password from mysql.user; 
+------+-----------+-------------------------------------------+
| user | host | password     |
+------+-----------+-------------------------------------------+
| root | localhost | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
| root | 127.0.0.1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
| root | ::1 | *E2ACEC2F2DA384EE6753673365DFEF35F0C272C9 |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> show databases; 
+--------------------+
| Database  |
+--------------------+
| information_schema |
| mysql  |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> exit
Bye

1.2.2 安装后的标准化操作

编写翻译安装或通用二进制安装后,日常都要求做一些附加的操作,富含安装意况变量、输出头文件和库文件、设置man路线。

echo "export PATH=/usr/local/mysql/bin:$PATH" >/etc/profile.d/mysql.sh
chmod +x /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
echo "MANPATH /usr/local/mysql/man" >>/etc/man.config

echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
ldconfig
ln -s /usr/local/mysql/include /usr/include/mysql

1.2.1 开首化数据库

不利用rpm包安装,就需求对mysql实行起始化以成立一些文件、库和钦点一些参数。但在伊始化mysql前,要事先做一些操作。

shell> mkdir -p /mydata/data
shell> useradd -r -s /sbin/nologin mysql
shell> chown -R mysql.mysql /usr/local/mysql
shell> chown -R mysql.mysql /mydata/data
shell> cd /usr/local/mysql
shell> scripts/mysql_install_db --datadir=/mydata/data --user=mysql
shell> chown -R root.root /usr/local/mysql

执行mysql_install_db时会在/tmp下创设有的时候表,所以mysql顾客需求对/tmp有写权限,不然实践实例开首化脚本时大概会报相通上边包车型地铁错误:
ERROR: 1 Can't create/write to file '/tmp/#sql_7a0e_0.MYI' (Errcode: 13)
那注明未有写权限,所以要求改革/tmp目录的权位:

chmod 1777 /tmp

同样,mysql_install_db始于时只要提醒已摈弃,则应用如下方法:

bin/mysqld --initialize-insecure --datadir=/mydata/data --user=mysql

起初化完成后,提供配置文件和劳动运营脚本。

shell> cp -a support-files/mysql.server /etc/init.d/mysqld
shell> cp -a support-files/my-default.cnf /etc/my.cnf  

# 修改my.cnf的datadir
shell> vim /etc/my.cnf 
[mysqld]
datadir=/mydata/data

如若是centos7,则提供如下服务运行脚本(如有必要,更改pid文件路线)。

shell> cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/var/run/mysqld/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Start main service
ExecStart=/usr/local/mysql-5.7.19/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

修改"root@localhost"密码。

shell> mysql
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> q

敞开防火墙

编辑:数据库 本文来源:CentOS 7.2 Yum编写翻译安装MySQL 5.6

关键词: