centos 7 yum 安装 MySQL 5.6 修改了 数据目录后,无法启动

waylau 发布于 2015/05/15 14:47
阅读 9K+
收藏 0
刚开始,安装默认步骤安装完 MySQL 是可以正常启动的。后来我就想把MySQL 的数据目录修改下路径。
这个是我记录的步骤,  http://www.waylau.com/centos-7-install-mysql/
 
主要是做了如下操作
   
 移动数据到数据存放目录

`/var/lib/mysql` 整个目录移到 `/home/data`,执行

    mv /var/lib/mysql /home/data
    
这样就把 MySQL 的数据文件移动到了 `/home/data/mysql` 下

修改 `/etc/my.cnf` 文件,

    [mysqld] 
    datadir=/home/data/mysql
    socket=/home/data/mysql/mysql.sock

    [mysql] 
    socket=/home/data/mysql/mysql.sock
    
切换到 MySQL 安装目录  /usr/bin,执行

    chown -R mysql .
    chgrp -R mysql .

而后 我再 执行 systemctl start  mysqld

就没有响应了,好像死掉一样,直到 我执行 ctr+c 来取消那个命令



看了下 日志 /var/log/mysqld.log

150515 14:44:12 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
150515 14:50:21 mysqld_safe Starting mysqld daemon with databases from /home/data/mysql
2015-05-15 14:50:22 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-15 14:50:22 0 [Note] /usr/sbin/mysqld (mysqld 5.6.24) starting as process 1761 ...
2015-05-15 14:50:22 1761 [Warning] Can't create test file /home/data/mysql/localhost.lower-test
2015-05-15 14:50:22 1761 [Warning] Can't create test file /home/data/mysql/localhost.lower-test
2015-05-15 14:50:22 1761 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)


2015-05-15 14:50:22 1761 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)


2015-05-15 14:50:22 1761 [Note] Plugin 'FEDERATED' is disabled.
2015-05-15 14:50:22 1761 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-05-15 14:50:22 1761 [Note] InnoDB: The InnoDB memory heap is disabled
2015-05-15 14:50:22 1761 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-05-15 14:50:22 1761 [Note] InnoDB: Memory barrier is not used
2015-05-15 14:50:22 1761 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-05-15 14:50:22 1761 [Note] InnoDB: Using Linux native AIO
2015-05-15 14:50:22 1761 [Note] InnoDB: Not using CPU crc32 instructions
2015-05-15 14:50:22 1761 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-05-15 14:50:22 1761 [Note] InnoDB: Completed initialization of buffer pool
2015-05-15 14:50:23 1761 [Note] InnoDB: Highest supported file format is Barracuda.
2015-05-15 14:50:23 1761 [Note] InnoDB: 128 rollback segment(s) are active.
2015-05-15 14:50:23 1761 [Note] InnoDB: Waiting for purge to start
2015-05-15 14:50:23 1761 [Note] InnoDB: 5.6.24 started; log sequence number 1654293
2015-05-15 14:50:23 1761 [Note] Server hostname (bind-address): '*'; port: 3306
2015-05-15 14:50:23 1761 [Note] IPv6 is available.
2015-05-15 14:50:23 1761 [Note]   - '::' resolves to '::';
2015-05-15 14:50:23 1761 [Note] Server socket created on IP: '::'.
2015-05-15 14:50:23 1761 [ERROR] Can't start server : Bind on unix socket: Permission denied
2015-05-15 14:50:23 1761 [ERROR] Do you already have another mysqld server running on socket: /home/data/mysql/mysql.sock ?
2015-05-15 14:50:23 1761 [ERROR] Aborting


2015-05-15 14:50:23 1761 [Note] Binlog end
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'partition'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_METRICS'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_CMPMEM'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_CMP'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_LOCKS'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'INNODB_TRX'
2015-05-15 14:50:23 1761 [Note] Shutting down plugin 'InnoDB'
2015-05-15 14:50:23 1761 [Note] InnoDB: FTS optimize thread exiting.
2015-05-15 14:50:23 1761 [Note] InnoDB: Starting shutdown...
2015-05-15 14:50:25 1761 [Note] InnoDB: Shutdown completed; log sequence number 1654303
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'ARCHIVE'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'BLACKHOLE'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'MEMORY'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'CSV'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'MyISAM'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'MRG_MYISAM'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'sha256_password'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'mysql_old_password'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'mysql_native_password'
2015-05-15 14:50:25 1761 [Note] Shutting down plugin 'binlog'
2015-05-15 14:50:25 1761 [Note] /usr/sbin/mysqld: Shutdown complete


150515 14:50:25 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended


是错在哪里?

加载中
0
Feng_Yu
Feng_Yu
看看日志输出呢?是不是卡在哪一步了?
waylau
waylau
回复 @Feng_Yu : 恩。设置SELinux 成为permissive模式,重启后 也是可以访问的
Feng_Yu
Feng_Yu
回复 @waylau : 建议还是招一个或者自己培训一个SA。程序员就不要乱搞产品环境了,否则以后接手的SA绝对会骂。至于Selinux这玩意,无论开还是不开都有自己的理由,决定权在SA手里。
waylau
waylau
@Feng_Yu 那 话说 在生产环境,我到底是需不需要启用 selinux 呢?话说,我们现在是想把java web项目从 window 迁移到 centos 上,。但是 现在公司又没有这方面 Linux 运维的人才。鉴于这种现状,你能给我哪些建议呢?谢谢指导
Feng_Yu
Feng_Yu
回复 @waylau : selinux经常会出现奇怪的权限问题。调试阶段通常关闭。全部调通之后最后调整selinux权限
waylau
waylau
回复 @Feng_Yu : 这招管用了,我重启就可以访问了。~ 但这是为什么呢??
下一页
0
Helloall
Helloall

你可以尝试重新初始化数据库

sudo /你的目录/mysql/scripts/mysql_install_db --user=mysql --basedir=/你的目录/mysql --datadir=/你的数据库目录

重新初始化之后,尝试能否启动?

waylau
waylau
[root@localhost ~]# /usr/bin/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/bin/mysql --datadir=/home/data/mysql -bash: /usr/bin/mysql/scripts/mysql_install_db: 不是目录
waylau
waylau
回复 @Helloall : [root@localhost ~]# whereis mysql mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz 是 /usr/bin/mysql 吗??
Helloall
Helloall
回复 @waylau : 打开终端,输入whereis mysql 命令,就可以列出与Mysql相关的目录了。
waylau
waylau
我是root 账户 用 yum 安装的,话说,他默认的安装目录是在哪里?
0
waylau
waylau
@Feng_Yu

 [root@localhost ~]# ps aux | grep mysql
root      1460  0.0  0.0 115212  1564 ?        Ss   15:17   0:00 /bin/bash /usr/bin/mysql-systemd-start post
root      2996  0.0  0.0 112656   972 pts/0    S+   15:20   0:00 grep --color=auto mysql


这个文件  /home/data/mysql/mysql.sock  是不存在的 
0
waylau
waylau
设置SELinux 成为permissive模式 重启是可以的,但是 这个为啥呢?
waylau
waylau
setenforce 0 ##设置SELinux 成为permissive模式 关了 还是一样 启动不了
0
orangleliu
orangleliu

我一开始也是这么做的,一直没解决,后来直接吧 mysql目录软链接到其他盘的目录。这样一个替代方案

0
purple_grape
purple_grape
chmod 755 /home/data
waylau
waylau
[root@localhost ~]# chmod 755 /home/data [root@localhost ~]# ls -Z /home/data drwxr-xr-x. mysql mysql system_u:object_r:user_home_t:s0 mysql 设置了还是不行
0
读一不二

骚年们, 你们都修改了  /usr/bin/mysql-systemd-start 这个文件吗?跟my.cnf一样,datadir和sock一样要修改的哦!

centos7.0+yum mysql 5.6下刚折腾好,费了大半天。

0
waylau
waylau

引用来自“夜雨轻茶”的评论

骚年们, 你们都修改了  /usr/bin/mysql-systemd-start 这个文件吗?跟my.cnf一样,datadir和sock一样要修改的哦!

centos7.0+yum mysql 5.6下刚折腾好,费了大半天。

        没动这个文件呢~,确定有效
0
李三石
李三石
/etc/apparmor.d/usr.sbin.mysqld  文件中的对应目录也需要修改
修改后重启apparmor:  service apparmor restart
返回顶部
顶部