CentOS 7.2 Yum编写翻译安装MySQL 5.6

作者:数据库

大器晚成、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

张开防火墙

本文由ca88发布,转载请注明来源

关键词: ca88网址 数据库系列 ca88会员入