Question

I'm trying to move the data directory of mysql, here are my steps:

  • use show variables like 'datadir' to know my datadir is /var/lib/mysql/
  • cd /var/lib/mysql/
  • # mv * /home/elderry/db/
  • gvim /etc/mysql/my.cnf
  • Add this line in [mysqld] section: datadir = /home/elderry/db/
  • # systemctl start mysqld

    Job for mysqld.service failed. See 'systemctl status mysqld.service' and 'journalctl -xn' for details.

  • Then I tried: systemctl status mysqld.service

Result:

mysqld.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled)
   Active: activating (start-post) (Result: exit-code) since Tue 2013-07-30 14:31:53 CST; 13s ago
  Process: 14174 ExecStart=/usr/bin/mysqld --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
  Control: 14175 (mysqld-post)
   CGroup: name=systemd:/system/mysqld.service
           └─control
             ├─14175 /bin/sh /usr/bin/mysqld-post
             └─14293 sleep 1

Jul 30 14:31:53 Kanone mysqld[14174]: 130730 14:31:53 [Warning] Can't create test file /home/elderry/db/Kanone.lower-test
Jul 30 14:31:53 Kanone mysqld[14174]: [71B blob data]
Jul 30 14:31:53 Kanone mysqld[14174]: 130730 14:31:53 [ERROR] Aborting
Jul 30 14:31:53 Kanone mysqld[14174]: 130730 14:31:53 [Note] /usr/bin/mysqld: Shutdown complete
Jul 30 14:31:53 Kanone systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
  • If I want to start mysql manually: mysql -u root -p output:

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)

What shoud I do for now?

Was it helpful?

Solution

It seems you moved the datadir to your home directory. I think that when you start mysqld via your service manager (in your case systemd) it will be started as an unprivileged user (most likely mysql). I strongly doubt that this user has privileges to access the homedir of the user elderry.

So the solution would either be moving your datadir to a more suitable location like /var/lib/mysql and chown this directory to the user under which mysql runs. Or that you give the mysql user privileges that he can acces the homedir of elderry.

OTHER TIPS

When installing MariaDB, it creates user and group mysql automatically that own all data files, so if you move data dir, make sure that all folder, subfoler, files in new data directory are owned by user mysql and group mysql.

Also check if your partition is not full, which was my case.

For an unknown reason, moving the data to another partition did not work either.

So for a quick fix, instead of messing with llvm or gparted, I reduced my /swapfile size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top