centos7mysql关闭服务报错_Centos7离线安装Mysql_解压包安装

安装记录:

1、首先创建一个目录用于存放解压的Mysql目录(可以使用原目录名,但是建议新建目录,这样方便管理和配置):

mkdir -p /opt/mysql

2、创建用户

[root@centos01 home]#

groupadd mysql

[root@centos01 home]#

useradd mysql -g mysql

修改mysql安装目录(这里是/opt/mysql )的权限:

chown -R mysql:mysql /opt/mysql

此外也可以使用以下的语句,两者效果一样,只不过上面的语句更简单;

[root@centos01 mysql]#

chown -R mysql .

[root@centos01 mysql]#

chgrp -R mysql .

3、 初始化mysql并启动mysql服务

由于 mysql5.7新特性, mysql_install_db 已经不再推荐使用了,建议改成 mysqld –initialize 完成实例初始化。

注意下面语句中的--basedir和--datadir两个参数的值,必须与mysql的安装路径一致,此外如果

--datadir中如果已经有数据,在初始化时会报错,此时需要将之前的 --datadir中的数据清空,之后在初始化

[root@centos01 mysql]#

cd /optmysql/bin

[root@centos01 bin]#

./mysqld --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --initialize

显示如下:随机密码 ,一定要记住该密码!!!!!!

2016-11-26T20:29:03.612269Z 1 [Note] A temporary password is generated for root@localhost: 9Kt9>u95ha%s

4、 尝试启动Mysql服务 ,

support-files/mysql.server start

通常情况下会报错:

[root@slave03 mysql]#

/opt/mysql/support-files/mysql.server start

support-files/mysql.server: line 271: cd: /usr/local/mysql: No such file or directory

Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)

5、 如果报上述错误,需要修改support-files下mysql.server文件,

修改配置文件:将66-73行/usr/local/修改为/home/

vim   /opt/mysql/support-files/mysql.server

然后重新开启mysq :

/opt/mysql/support-files/mysql.server start

6、关闭selinux:

vim /etc/selinux/config

解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出

如果重启Mysql仍然报错,重启机器试试

7、将mysql的启动时读取的系统配置文件改掉:

mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件 ,故需要将其修改使Mysql无法读取到该文件

修改配置文件的名称:

mv /etc/my.cnf /etc/my.cnf.old

8、重启服务

/opt/mysql/support-files/mysql.server start

若服务已经启动可以使用以下语句找到mysql并将其kill掉:

ps -ef | grep mysql

9\登录:

/opt/mysql/bin/mysql -uroot -p

之后 修改密码:

set password=password('youpassword');

10、查看有哪些用户

use mysql;

select Host,User from user;

给权限:

GRANT ALL PRIVILEGES ON *.* TO root@'%' identified by 'youpassword';

flush privileges;

11\

创建用户:

CREATE USER 'oozie'@'%' IDENTIFIED BY 'oozie';

权限:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO 'oozie'@'%' IDENTIFIED BY 'oozie' WITH GRANT OPTION;

问题记录:

root@slave02 support-files]# ./mysql.server start

Starting MySQL./opt/mysql/bin/mysqld_safe: line 548: /var/lib/mysql/mysqld_safe.pid: No such file or directory

awk: (FILENAME=- FNR=1) warning: error writing standard output (Broken pipe)

.touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

/opt/mysql/bin/mysqld_safe: line 135: /var/log/mariadb/mariadb.log: No such file or directory

/opt/mysql/bin/mysqld_safe: line 169: /var/log/mariadb/mariadb.log: No such file or directory

touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory

chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory

/opt/mysql/bin/mysqld_safe: line 135: /var/log/mariadb/mariadb.log: No such file or directory

ERROR! The server quit without updating PID file (/var/lib/mysql/slave02.yscredit.com.pid).

--------------------------------------------------------------------------------------------------

解决:

mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。

解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data

原配置文件中内容如下:

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]

log-error=/var/log/mariadb/mariadb.log

pid-file=/var/run/mariadb/mariadb.pid

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

修改过后:

[mysqld]

datadir=/opt/mysql

socket=/opt/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]

log-error=/opt/mysql/log/mariadb/mariadb.log

pid-file=/opt/mysql/mariadb/mariadb.pid

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

=================================================================================================

之后启动mysql:

[root@slave02 support-files]# ./mysql.server start

Starting MySQL.... ERROR! The server quit without updating PID file (/opt/mysql/slave02.yscredit.com.pid).

依然报错。

此时解决:

selinux惹的祸,如果是centos系统,默认会开启selinux

解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。

同时:参考https://www.justin.my/2012/03/starting-mysql-error-the-server-quit-without-updating-pid-file

Sometimes you may see this error in your server. But don’t panic, just rename or move away the /etc/my.cnf in your server, and try to restart the MySQLd again.

[root@server:~ ] $ service mysqld start

Starting MySQL... ERROR! The server quit without updating PID file (/var/lib/mysql/server.pelayan.com.pid).

[root@server:~ ] $ mv /etc/my.cnf /etc/my.cnf.old

[root@server:~ ] $ service mysqld restart

Shutting down MySQL.... SUCCESS!

Starting MySQL.. SUCCESS!

[root@server:~ ] $

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值