Fail to move mysql's data directory - mysql

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?

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.

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.

Related

Moving MySQL datadir on development machine

Operating System: Ubuntu 18.04
MySQL version: Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)
My system is set-up so that Ubuntu is running on a 128gb SSD, with a separate 1TB SSD for storage. This system is dual-boot with Windows 10 Pro and Ubuntu 18.04. The storage drive is NTFS formatted.
I would like to move the MySQL datadir over to the storage drive, because my OS drive isn't big enough.
I've been following the tutorial on this URL: https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04
I've gotten to "Step 4 — Restarting MySQL" in the tutorial. Up to this point, I've followed everything to a T, no missed commas, forward slashes, etc. All done exactly as described (I've checked to make sure this is true numerous times)
When I enter the terminal command
sudo systemctl start mysql
I get the following output
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
Following this output, I enter the following command into the terminal
systemctl status mysql.service
and receive the following output
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-03-31 22:36:46 CDT; 38s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 7368 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 7316 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 7368 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
Error: 13 (Permission denied)
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.436713Z 0 [Warning] [MY-010091] [Server] Can't create test file /media/user/storage/mysql_datadir/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.436796Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 7368
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.439912Z 0 [Warning] [MY-010091] [Server] Can't create test file /media/user/storage/mysql_datadir/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.439923Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /media/user/storage/mysql_datadir/mysql/ is case insensitive
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.439961Z 0 [ERROR] [MY-013276] [Server] Failed to set datadir to '/media/user/storage/mysql_datadir/mysql/' (OS errno: 13 - Permission denied)
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.440049Z 0 [ERROR] [MY-010119] [Server] Aborting
Mar 31 22:36:46 user-desktop mysqld[7368]: 2020-04-01T03:36:46.440146Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL.
Mar 31 22:36:46 user-desktop systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Mar 31 22:36:46 user-desktop systemd[1]: mysql.service: Failed with result 'exit-code'.
Mar 31 22:36:46 user-desktop systemd[1]: Failed to start MySQL Community Server.
Seeing that this was a permissions error (which should have been avoided using the -av tags when copying the original directory to the new drive) I entered in the following command to give open permissions to the entire drive.
sudo chmod a+rwx /media/user/storage/
to check the permissions I enter
ls -ls /media/user/storage/mysql_datadir
with output
total 12
12 drwxrwxrwx 1 root root 12288 Mar 31 02:45 mysql
I've also made sure the full file path to the new datadir is lowercase to avoid conflict between the two file systems.
I still cannot get MySQL to start.
I'd appreciate any help. Thank you in advance.
Edit:
namei -mo /media/user/storage/mysql_datadir
f: /media/user/storage/mysql_datadir
drwxr-xr-x root root /
drwxr-xr-x root root media
drwxr-x--- root root user
drwxrwxrwx root root storage
drwxrwxrwx root root mysql_datadir
Based on your post seems that you are having permission issue along with owner of the "data directory" must always be mysql.
STOP your mysql service if it's running.
Consider below example:
my.cnf looks:
#
# Original path change to avoid space issue on server
#
datadir=/var/lib/mysql
Now you change this datadir in your my.cnf file like:
#
# Original path change to avoid space issue on server
#
#datadir=/var/lib/mysql
datadir=/media/user/storage/mysql_datadir
After this check the permission:
cd /media/user/storage/mysql_datadir
ls -al
output:
drwxr-x--x 40 mysql mysql 4096 Mar 27 00:01 mysql
If this is not output then execute below command:
chmod -Rf 0751 /media/user/storage/mysql_datadir
chown -Rf mysql:mysql /media/user/storage/mysql_datadir
Finally
START your mysql service now.
I had the same problem/solution as Pratik, after following the instructions to define a new datadir in
/etc/mysql/mysql.conf.d/mysqld.conf
and
/etc/apparmor.d/usr.sbin.mysqld
I modified my fstab to mount to
/mnt
instead of
/media/[username]
and mysql start up without any errors. no additional permissions to set other than the mysql directory. My issue was on Ubuntu 18.04 must be something special about the /media mount point

Moving Mysql data directory

I am having trouble moving my mysql data directory to a new location. I am running Linux Mint 17, MySQL 5.7.19. I have tried the instructions in these two locations:
How to change MySQL data directory?
This answer:
https://stackoverflow.com/a/10209282/7850358
and this guide:
https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04
I believe I am having a similar problem as this question: https://dba.stackexchange.com/questions/101732/how-do-i-move-a-mysql-data-directory-to-an-external-hard-drive
I rsync'ed the data from /var/lib/mysql to /media/mike/DataBase. The directory exists, and is properly specified in the /etc/mysql/mysql.conf.d/mysqld.cnf, and I created an alias in /etc/apparmor.d/tunables/alias. I made sure the permissions on the folder were correct: drwx------ 11 mysql mysql 4096 Jan 21 16:52 mysql.
I restart apparmor, no problems.
I restart the mysql server - I get this:
Thudbucket mike # sudo systemctl start mysql
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
Thudbucket mike # systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit-code) since Sun 2018-01-21 17:10:34 EST; 12s ago
Process: 22295 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 22288 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 22295 (code=exited, status=1/FAILURE); : 22296 (mysql-systemd-s)
CGroup: /system.slice/mysql.service
└─control
├─22296 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─22332 sleep 1
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.308875Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.308930Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.453972Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server opti
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.454033Z 0 [Warning] Can't create test file /media/mike/DataBase/mysql/Thudbucket.lower-test
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.454054Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.19-0ubuntu0.16.04.1) starting as process 22295 ...
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.455725Z 0 [Warning] Can't create test file /media/mike/DataBase/mysql/Thudbucket.lower-test
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.455735Z 0 [Warning] Can't create test file /media/mike/DataBase/mysql/Thudbucket.lower-test
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.455760Z 0 [ERROR] failed to set datadir to /media/mike/DataBase/mysql/
Jan 21 17:10:34 Thudbucket mysqld[22295]: 2018-01-21T22:10:34.455774Z 0 [ERROR] Aborting
Jan 21 17:10:34 Thudbucket systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
I've tried just about everything I could find online. I even read the manual, for a change. For some reason, moving the data directory to any location but /var/lib/mysql results in errors for me.
I ultimately had better luck with this hack:
https://askubuntu.com/a/663945/785778
## copy with permissions intact:
rsync -avzh /var/lib/mysql /path/to/new/place
## back up original
mv /var/lib/mysql /var/lib/_mysql
## create a new empty directory in place of old:
mkdir /var/lib/mysql
## bind mount the new location to the old:
mount -B /path/to/new/place /var/lib/mysql
After restarting the mysql, everything worked fine.
Ironically - symbolic linking did not work
EDIT
This appears to be a bug, but the provided solution doesn't resolve the issue for me:
https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1574782
https://forums.mysql.com/read.php?11,653198,653198#msg-653198
The bug works like this: MySQL at startup looks for the presence of the /var/lib/mysql/ and /var/lib/mysql/mysql directories. The solution provided to leave the /var/lib/mysql and /var/lib/mysql/mysql directories but remove the contents and add the new datadir path to the apparmor configuration file (/etc/apparmor.d/usr.sbin.mysqld) and reload it (/etc/init.d/apparmor reload).
But to repeat, while it appears I have the same issue (MySQL keeps looking for the datadir at /var/lib/mysql), the only solution that worked for me was to mount the data directory at /var/lib/mysql/.
Return this error
2021-02-12T19:02:55.910704Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2021-02-12T19:02:55.910710Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
2021-02-12T19:02:55.910731Z 0 [ERROR] Aborting

MySQL doesn't start at all

This is awsome yesterday I got the same error and I debugged it but today I don't remember what to do since I did it to fast.
When I'm doing:
service mysql start
I get this message:
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.
For this reason I did:
systemctl status mysql.service
and get:
Apr 16 18:11:25 darphus.xen.prgmr.com systemd[1]: Unit mysql.service entered failed state.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: mysql.service holdoff time over, scheduling restart.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Stopping MySQL Community Server...
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Starting MySQL Community Server...
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: mysql.service start request repeated too quickly, refusing to start.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Failed to start MySQL Community Server.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Unit mysql.service entered fai
journalctl -xn give:
Logs begin at Sun 2017-04-16 17:58:44 UTC, end at Sun 2017-04-16 18:16:35 UTC
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/pickup[938]: warning: 868F625E66:
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/pickup[938]: 868F625E66: uid=0 fro
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/proxymap[941]: warning: mysql:/etc
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/cleanup[1361]: warning: proxy:mysq
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/cleanup[1361]: warning: 868F625E66
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/pickup[938]: warning: 8744E25E66:
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/pickup[938]: 8744E25E66: uid=0 fro
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/proxymap[941]: warning: mysql:/etc
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/cleanup[1362]: warning: proxy:mysq
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/cleanup[1362]: warning: 8744E25E66
I think a tryed all the trick on the internet and nothing work for today.
Please help me since All my website are down for this reason.
The answer by #Lotfio Lakehal will fix your issues but should be considered a last resort - you certainly wouldn't want to run this on a database that had data you require as it will remove all your configuration values in the process. A better way would be to find out what is causing the issue in your my.cnf and fix it. MySQL has this ability built in.
mysqld --help --verbose
The above command will simulate starting your mysql server. If it can't it will give an error message and a description of what is wrong with the config files.
For instance I set up a test config file with some invalid data and when I ran the above command I got the following:
error: Found option without preceding group in config file: /etc/mysql/my.cnf at line: 22
This allows me to easily go to the configuration file and remove or edit the offending configuration, hopefully, allowing you to fix the said config file without having to do a full reinstall of the server.
Just to clarify this is in no way a put down on this answer, the previous answer will fix 99% of all issues but should be considered a last resort. Ideally, you want to fix the issue and understand why it occurred so you don't make the same mistakes in the future.
Usually this problem appears when you try to change something in the /etc/mysql/my.cnf.
WARNING
The following solution will delete all your database data! Try other solutions first.
Reinstalling MySQL may solve the problem, but should only be used as a last resort! To reinstall:
sudo apt purge mysql-server mysql-common
sudo apt autoremove mysql-server mysql-common
and reinstall it again
sudo apt-get update
sudo apt-get install mysql-server
check this out:
https://askubuntu.com/questions/392438/mysql-job-failed-to-start
note : This solution will delete all your database data ! So be aware of what you are doing .
I had the same problem running on ubuntu 18.04 with mysql 5.7. The first thing that I did was to go to mysql error log, it should be in /var/log/mysql/error.log.
There I found the following line:
[ERROR] InnoDB: Cannot allocate memory for the buffer pool
So looked like a memory issue, I checked the syslog for mentions of MySQL:
grep mysql syslog
Which displayed this:
kernel: [21270406.665399] Out of memory: Kill process 9674 (mysqld) score 251 or sacrifice child
I checked that I had ‘spare memory’ in the form of swap.
free -m
Which displayed this:
total used free shared buff/cache available
Mem: 985 522 69 45 393 276
Swap: 0 0 0
This meant that we have to setup swap space:
Swap: 0 0 0
In my case, mysql is on DigitalOcean and their guides are great so I defer you to the following:
How To Add Swap Space on Ubuntu 18.04
This answer should be read in conjunction with #"James Lendrem" answer.
If you changed or added anything to the mysql configuration files, try removing what you did.
First check the syslog file, which may give you a clue:
grep mysql /var/log/syslog | grep ERROR
This command searches the syslog for any reference to the term "mysql", and then limit those results to ones containing "ERROR".
Next look in the various config files. If you edited a specific config file, start there. Otherwise, look in all the config files in these directories:
ls -l /etc/mysql/*.cfg
ls -l /etc/mysql/mysql.conf.d/
ls -l /etc/mysql/conf.d/
If you change anything in any of the config files, (re)start the mysql server:
service mysql restart
# or else you could use for the first time:
service mysql start
I had the same problem running on ubuntu 18.04 with mysql 5.7
In log files I found the following lines:
Jul 13 01:25:35 r-lap audit[11196]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=11196 comm="mysqld" req
Jul 13 01:25:35 r-lap kernel: audit: type=1400 audit(1531425335.671:116): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/
On stopping apparmor, mysql start was successful with a message that ssl support could not be enabled. Stop the service.
To generate the certs,
Run
sudo mysql_ssl_rsa_setup --datadir /var/lib/mysql
The datadir may be different in your case.
Then do
sudo -i
cd /var/lib/mysql
chown mysql:mysql ./*
This will set the permissions for the generated cert and key files right.
Next you can start both apparmor and then mysql.
This fixed the issue in my case.
Since I did not try separately, I don't know whether it's the apparmor restart or generating the ssl key and certs that fixed the issue.
Note: I later found out this thread
For me, I ran some cache clearing operations to free up space using tools like Stacer, and then MySQL started showing problems.
Use this to get some clues first
grep mysql /var/log/syslog | grep ERROR
If the error says, Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
then clearly, the log files were cleaned up.
Use this to first create the MySQL directory and grant all permissions for MySQL to use that folder.
> sudo mkdir /var/log/mysql
> sudo chown -R mysql:mysql /var/log/mysql
> sudo service mysql restart
This solution has nothing to do with the my.cnf files and is completely safe on data.
Try running journalctl -u mysql.service to figure out why the error is happening.
Also, systemd cat mysql.service will show you the Service Unit file that describes your service - there might be errors.

Mariadb doesn't starts. Control process Exited

I am trying to start mariadb with systemctl start mariadb also tried using sudo along.
This is what it says
Job for mariadb.service failed because the control process exited with
error code. See "systemctl status mariadb.service" and "journalctl
-xe" for details.
I saw this at many places but nothing helped.
It fails, I removed, installed again, nothing happened.
This is a part of /var/log/messages
Jun 17 18:03:09 controller systemd: Starting MariaDB 10.1 database
server...
Jun 17 18:03:09 controller mysqld: 2016-06-17 18:03:09 140477178509440
[Note] /usr/libexec/mysqld (mysqld 10.1.12-MariaDB) starting as process 120408 ...
Jun 17 18:03:12 controller systemd: mariadb.service: main process exited, code=exited, status=1/FAILURE
Jun 17 18:04:13 controller systemd: mariadb.service: control process exited, code=exited status=3
Jun 17 18:04:13 controller systemd: Failed to start MariaDB 10.1 database server.
Jun 17 18:04:13 controller systemd: Unit mariadb.service entered failed state.
Jun 17 18:04:13 controller systemd: mariadb.service failed.
I am really new to CentOS and mariadb, so I don't know how to proceed.
EDIT
The mariadb.log says
2016-06-17 19:24:39 140652810123392 [Note] Server socket created on IP: '::'.
2016-06-17 19:24:39 140652810123392 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 98: Address already in use
2016-06-17 19:24:39 140652810123392 [ERROR] Do you already have another mysqld server running on port: 3306 ? 2016-06-17 19:24:39 140652810123392 [ERROR] Aborting
This is my my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# This group is read by the server
#
[mysqld]
port=5555
bind-address = 10.23.77.68
default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
I tried adding a line in my.cnf
port=5555
Didn't help, mariadb.log says the same thing as I have mentioned earlier.
I solved as follows:
After installing
Run: > mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/
Then: >mysql_secure_installation
And then: systemctl start mariadb
With this this, I can resolved.
Just remove following files at location
/var/lib/mysql
ib_logfile0
ib_logfile1
fuser -k 3306/tcp will solve the probem.
-k is to Kill processes accessing the file.

Archlinux mysqld won't launch

Cat' launch mysqld on my archlinux x64.
Job for mysqld.service failed. See "systemctl status mysqld.service" and "journalctl -xe" for details.
after systemctl start mysqld
in log
mysqld.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: timeout) since Mon 2015-04-06 22:07:24 UTC; 9ms ago
Process: 18077 ExecStart=/usr/bin/mysqld --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
Main PID: 18077 (code=exited, status=1/FAILURE)
CGroup: /system.slice/mysqld.service
`-control
Apr 06 22:07:24 atlas systemd[1]: Failed to start MariaDB database server.
Apr 06 22:07:24 atlas systemd[1]: Unit mysqld.service entered failed state.
Apr 06 22:07:24 atlas systemd[1]: mysqld.service failed.
What can i do? Thanks!
You will get detailed info in systemd journal: sudo journalctl -f then, on an other terminal, start mysql: sudo systemctl start mysqld to get logs on the first terminal. You will likely get error messages that will help you figure out what goes wrong.
You should type this command before starting the service
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
ِAnd later you can start the service Regularly
For one session:
systemctl start mysqld
OR being enabled automatically on startup << (NOT RECOMMENDED)
systemctl enable mysqld
Did you follow the install instruction on the ArchLinux Wiki ?
https://wiki.archlinux.org/index.php/MySQL#Installation
As mentionned by Medo Tareq, you need to run the following command :
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
(Obviously you can adjust the parameters on the command, if you know what you are doing.)
The Wiki page also has other hint and information, notably about the mysql_secure_installation command that "will interactively guide you through a number of recomended security measures at the database level".
Try change the permission of MySQL folder. If you are working locally and try to reinstall MySQL again after runing this command, it will work.
sudo chmod -R 755 /var/lib/mysql/