After changing the data directory, MySQL fails to start?

Problem Analysis: The data directory needs to be changed. Changing the data directory directly in the configuration file and restarting causes the database to fail to start normally?


The solution can be checked in the following three steps :
① Check whether the configuration file is correctly configured, whether the specified data directory is correct, and whether the pid file path is correct
② Check whether the permissions of the data directory are MySQL users and groups

③ If none of the above ①② fails, you can try to unmount the NAS directory and re-initialize the database (the data will be deleted, consider whether to back it up):

    i)停止运行的数据库
    i)删除原来的数据目录 /opt/mysql_data
    i)重新创建新的数据目录,并授予MySQL用户与组权限
    例如:要将数据目录更改为/test/mysql/data/ 
        mkdir /test/mysql/data/
        chown  -R mysql:mysql   /test/mysql/data/
    i)进入到安装目录执行初始化:
     cd  /opt/mysql/    
     ./scripts/mysql_install_db  --user=mysql --basedir=/opt/mysql --datadir=/test/mysql/data/  --defaults-file=/etc/my.cnf --random-passwords
    i)修改配置文件里的数据目录指定datadir=/test/mysql/data/;启动数据库
    i)修改初始密码:
        cat  /root/.mysql_secret
        mysql -uroot -p
		mysql> SET PASSWORD = PASSWORD('123456'); 

Guess you like

Origin blog.csdn.net/T_LOYO/article/details/130642650