I'm trying to change the data directory of my MySQL database from the default location /var/lib/mysql to a new path which in my case is /home/dev/Desktop/iiab/db/mysql.
I have tried following the answer provided by Victor in the following post:
How to change MySQL data directory?
(I have also edited the alias file as per the instruction from mak in the comments on Victor's answer).
BUT, I am getting the following terminal error when trying to start MySQL again:
mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
When inspecting the log file using below command
tail -f /var/log/mysql/error.log
It shows the following:
2016-05-23T13:43:11.608141Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2016-05-23T13:43:11.608234Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-05-23T13:43:11.608252Z 0 [ERROR] Failed to initialize plugins.
2016-05-23T13:43:11.608260Z 0 [ERROR] Aborting
2016-05-23T13:43:11.608297Z 0 [Note] Binlog end
2016-05-23T13:43:11.608416Z 0 [Note] Shutting down plugin 'MyISAM'
2016-05-23T13:43:11.608469Z 0 [Note] Shutting down plugin 'CSV'
2016-05-23T13:43:11.609124Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
My my.cnf file looks as follows (I omitted the initial comments ##):
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[mysqld]
datadir=/home/dev/Desktop/iiab/db/mysql
socket=/home/dev/Desktop/iiab/db//mysql.sock
My /etc/apparmor.d/usr.sbin.mysqld file looks as follows (I only included the parts which were affected by the instructions i.e. replace var/lib/mysql with the new path).
# Allow data dir access
/home/dev/Desktop/iiab/db/mysql/ r,
/home/dev/Desktop/iiab/db/mysql/** rwk,
# Allow data files dir access
/home/dev/Desktop/iiab/db-files/ r,
/home/dev/Desktop/iiab/db-files/** rwk,
# Allow keyring dir access
/home/dev/Desktop/iiab/db-keyring/ r,
/home/dev/Desktop/iiab/db-keyring/** rwk,
My /etc/apparmor.d/tunables/alias file looks as follows (I omitted initial comments ##):
# Or if mysql databases are stored in /home:
alias /var/lib/mysql/ -> /home/dev/Desktop/iiab/db/mysql/,
I am able to restart and reload apparmor successfully.
I'm using Ubuntu 16.04.
Anyone know what I am doing wrong?
Related
I am using Ubuntu to configure Wordpress on WSL. Currently, I am trying to install MySQL as part of the LAMP Stack using the following as per this tutorial:
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start
When I run the second command, I see "fail" in red appear (ie. mysql won't start). Here is what the Error Log looks like:
2021-09-05T08:17:59.936284Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2021-09-05T08:17:59.951837Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)
2021-09-05T08:17:59.962000Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
2021-09-05T08:17:59.962006Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
2021-09-05T08:18:00.172509Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
2021-09-05T08:18:00.172578Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2021-09-05T08:18:00.172626Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-09-05T08:18:00.178880Z mysqld_safe mysqld from pid file /run/mysqld/mysqld.pid ended
Edit- Here is what I get when I run the following commands:
root#DESKTOP-P44T17P:~# stat /var/lib/mysql-files
stat: cannot stat '/var/lib/mysql-files': No such file or directory
root#DESKTOP-P44T17P:~# grep user /etc/mysql/mysql.conf.d/mysqld.cnf
user = mysql
It does not look the mysql-files directory exists.
Ubuntu 20.04.2
it might be your log folder deleted for some reason. make sure there's /var/log/mysql folder. if it's don't just make new one with mysql ownership.
Ensure the directory /var/lib/mysql-files exists and MySQL should start.
You can try:
sudo mkdir /var/lib/mysql-files
So I created my .bash_profile, opened it in a text editor and added:
export PATH=$PATH:/usr/local/mysql/bin
and then I saved it. Next, I tried running
sudo /usr/local/mysql/support-files/mysql.server start
was told to enter my password (so I did), and then terminal said
Starting MySQL
and then it kept printing dots until it said:
ERROR! The server quit without updating PID file (/usr/local/mysql/data/Nicks-MacBook-Pro.local.pid).
The error logs look like:
2021-01-25T20:50:49.707062Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.23) starting as process 15092
2021-01-25T20:50:49.710232Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2021-01-25T20:50:49.834599Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-25T20:50:49.943719Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-01-25T20:50:50.037810Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2021-01-25T20:50:50.125494Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-01-25T20:50:50.126128Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-01-25T20:50:50.151069Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.23' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server - GPL.
~
~
~
~
~
(END)
How do I fix this?
You should try to restart MySQL service after performing each step to check if the error is solved.
But first, take a full backup of MySQL data directory /var/lib/mysql/ before you make any changes to MySQL service.
Connect to your server via SSH as root user and restart MySQL manually. Sometimes restarting the MySQL server may fix this issue. You can use either of the following command to restart MySQL server.
/etc/init.d/mysql restart
or
service mysql restart
You need to check whether the MySQL service is already running. If MySQL service is already running, you will have to kill them and start again. Use the following command to check if there is a MySQL service running already.
ps -aux | grep -i mysql
If MySQL service is already running, you will get list of MySQL processes with PIDs. The PID is the process ID of the MySQL processes. You will have to kill those processes.
kill -9 PID
PID – Process ID of the MySQL process.
Check the ownership of MySQL data directory /var/lib/mysql/. Use the following command to check ownership of MySQL service
ll -aF /var/lib/mysql/
If it’s owner is root, you should change the ownership to MySQL or your user by using the following command.
chown -R mysql /var/lib/mysql/
Take a backup of mysql.sock file and remove it. To achieve this, use the following commands:
cp /var/lib/mysql.sock /var/lib/mysql.sock_bkp
rm -rf /var/lib/mysql.sock
Remove MySQL configuration file /etc/my.cnf or just back it up for now and restart:
mv /etc/my.cnf /etc/my.cnf.bak
Remove the log file named ib_logfile in the MySQL data directory /var/lib/mysql/ or just back it up now and restart the MySQL service. Sometimes MySQL service fails to start when it faces difficulty in updating the log files. The log files will be created automatically once you restart the MySQL service. Use the following command to remove the log files and back it up.
Change the present working directory to MySQL data directory.
cd /var/lib/mysql
Backup and remove the log files by renaming them.
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
Move the backups to a temporary location.
mv /var/lib/mysql/ib_logfile* /tmp/folder/
Find the log files with suffix “.err” in the MySQL data directory /var/lib/mysql/. These files contain the actual error message. You can use any editor or command like cat, less to read the error message from the log files.
cat /var/lib/mysql/yourservername.err
In many cases, MySQL will run soon after removing this error files.
rm -rf /var/lib/mysql/yourservername.err
Im going to install mysql to linux server. But I dont have root access to that server. So I created two folders called mysql and mysqldata. mysql folder holds binary files. mysqldata folder holds data and the logs.
my.cnf
[mysqld]
user = mysql
port = 3306
bind-address = localhost
basedir = /home/nwn/mysql/mysql-8.0
socket = /home/nwn/mysqldata/instA/socket/mysql.sock
datadir = /home/nwn/mysqldata/instA/data
tmpdir = /home/nwn/mysqldata/instA/tmp
secure_file_priv = /home/nwn/mysqldata/instA/mysql-files
max_connections = 150
# Logging
log-bin = /home/nwn/mysqldata/instA/logs/instA-binlog
log-error = /home/nwn/mysqldata/instA/logs/instA-errorlog.err
slow_query_log = 1
slow_query_log_file = /home/nwn/mysqldata/instA/logs/instA-slowquery.log
long_query_time = 0.5
# InnoDB
innodb_data_home_dir = /home/nwn/mysqldata/instA/innodb/data
innodb_data_file_path = ibdata1:50M;ibdata2:12M:autoextend:max:500M
innodb_log_group_home_dir = /home/nwn/mysqldata/instA/innodb/log
innodb_buffer_pool_size = 32M
# MyISAM
key_buffer_size = 16M
server_id = 1
I did all the other configurations.
when I run following command
mysql-8.0]$ bin/mysqld --defaults-file=~/mysqldata/instA/my.cnf --initialize-insercure
I have following logs in the error_log
cat ~/mysqldata/instA/logs/instA-errorlog.err
2018-10-09T10:39:51.127424Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8160)
2018-10-09T10:39:51.127523Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 432 (requested 4000)
2018-10-09T10:39:51.383986Z 0 [Warning] [MY-010101] [Server] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
2018-10-09T10:39:51.384043Z 0 [System] [MY-010116] [Server] /home/nwn/mysql/mysql-8.0/bin/mysqld (mysqld 8.0.12) starting as process 32654
2018-10-09T10:39:51.386625Z 0 [Warning] [MY-010122] [Server] One can only use the --user switch if running as root
2018-10-09T10:39:51.394675Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
2018-10-09T10:39:51.394817Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2018-10-09T10:39:51.394831Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-10-09T10:39:51.395363Z 0 [System] [MY-010910] [Server] /home/nwn/mysql/mysql-8.0/bin/mysqld: Shutdown complete (mysqld 8.0.12) MySQL Community Server - GPL.
Even though the post is very old, but posting my solution as it took me around 2 hours to figure it out and this can help someone save that time.
You can try doing :
shell> mysqld --initialize
This shall initialse the data directory in the path where you have installed MySql server. Generally placed at C:\Program Files\MySQL\MySQL Server 8.0.
Hope it helps someone.
Please follow these steps to reset your MySQL Password on Windows:
Stop MySQL Service # services.msc
Create file change_mysql_pwd.txt with following content (replase YourNewPassword with desired new password you want to have for root user:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'YourNewPassword';
Save the file under C:\ change_mysql_pwd.txt
Run CMD.exe as Admin (Start->Cmd->Right Click->Run as Administrator)
Type in cmd: cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
Create “Data” Folder under "C:\Program Files\MySQL\MySQL Server 8.0\ (if already exists delete its contents!)
Type in cmd: mysqld --install
Type in cmd: mysqld --initialize
Type in cmd: mysqld --init-file=C:\\change_mysql_pwd.txt
Login with root user account and the password set above.
Delete C:\ change_mysql_pwd.txt file
Enjoy...
(context: new setup, mysql 8 on windows server 2016)
What really helped me to get rid of "Failed to find valid data directory" was:
mysqld --initialize --console
The --console part tells you straight away on the command line what is wrong and what to do. Because I had a clean install, i lacked the "data" directory. However if you have settings in your my.ini that are not supported in the newly installed version, a "data" directory will be generated nevertheless with the command listed above. If you have more then one faulty setting in my.ini, you'll need to delete the newly created "data" directory first.
CAUTION: check first if you have databases in the data directory, else you'll loose all your databases!! So only use this on fresh installs.
In steps:
run mysqld --initialize --console from a cmd as administrator
fix the my.ini faulty line, delete the data directory (ONLY IF YOU HAVE A NEW INSTALLATION: else you'll loose all your databases!)
rerun mysqld --initialize --console
repeat until all errors are fixed.
Now MySql should start.
As far as I understand from your console output you try to initialize the database while there exist files in your data directory. First you should remove all files (please be careful here, you may loss your data) in the data directory of your MySQL, and then you should run the command below
shell> mysqld --initialize --console
as stated by #Alex Karshin, #Lazycoder_0071 and #Freeze_H. MySQL should initialize the database seamlessly if there isn't another problem.
What Kevin Kopf and Lazycoder_007 indicate in https://stackoverflow.com/a/62003723/7733418 worked for me fine, along with
deleting the files within the "data" folder before initialization (thanks to P D)
running mysqld --initialize in cmd as administrator
In 2000 I had installed XAMPP 1.7.3 on my Windows 7 64 Bit machine in F:/xampp. I always started the XAMPP Control Panel Application from this folder, clicked on the "Start" buttons for the MySQL and the Apache so it looked like this:
https://docs.moodle.org/19/de/images_de/e/e6/29_Apache_Stop-de.png
I recently decided to install the XAMPP 5.6.3 version to F:/xampp2. I imported another database and working on this new database was fine.
However, for some reason I cannot start the MySQL server in the F:/xampp any more. The Apache server does start. But when I click on the "Start" button in the XAMPP Control Center the text "Running" flashes up in green for a second (see linked picture above) and vanishes again. Nothing happens. In (this version 2.5.8 of) the Control Panel no additonal info is displayed in the log.
I tried everything to avoid a duplicate posting:
The other Mysql server in F:/xampp2 not running. The Port Check function of the Control Panel says 3306 is free.
Skype is not running.
There is no mysqld.exe in the Windows Task Manager
Checked services.msc - there is nothing running related to MySQL.
I ran netstat in a command line and there was no sign of 3306 anywhere.
I changed 3306 to 3307 in the f:/xampp/mysql/bin/my.ini. Nothing!
There are many threads like this one and I tried everything except to "delete and reinstall". I cannot delete F:/xampp - I have 500 GB and 500 tables of data in the F:/xampp MySQL database that my life depends on. I do not even want to touch the data in there and risk any loss. I cannot delete F:/xampp2 either. What can I do?
Thanks!
EDIT: I tried the following in the commandline:
f:\xampp\mysql\bin\mysqld.exe
150602 6:03:24 [Warning] Can't create test file \usr\local\mysql\data\MY-PC.lower-test
150602 6:03:24 [Warning] Can't create test file \usr\local\mysql\data\MY-PC.lower-test
f:\xampp\mysql\bin\mysqld.exe: Can't change dir to '\usr\local\\mysql\data\' (Errcode: 2)
150602 6:03:24 [ERROR] Aborting
150602 6:03:24 [Note] f:\xampp\mysql\bin\mysqld.exe: Shutdown complete
EDIT 2: I looked for the mysql.err file in f:\xampp\mysql\data.
150602 7:04:01 [Note] Plugin 'FEDERATED' is disabled.
InnoDB: Error: log file \xampp\mysql\data\ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 1073741824 bytes!
150602 7:04:01 [ERROR] Plugin 'InnoDB' init function returned error.
150602 7:04:01 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
150602 7:04:01 [ERROR] F:\xampp\mysql\bin\mysqld.exe: unknown variable 'innodb_file_format=barracuda'
150602 7:04:01 [ERROR] Aborting
150602 7:04:01 [Note] F:\xampp\mysql\bin\mysqld.exe: Shutdown complete
EDIT 3: Thanks for your comment, I tried the following but it there are other errors:
f:\xampp\mysql\bin\mysql --help
gives me inter alia:
Default options are read from the following files in the given order:
C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf f:\xampp\mysql\my.ini f:\xampp\mysql\my.cnf
then i try this line and I know that the my.ini file is there:
f:\xampp\mysql\bin\mysqld.exe --defaults-extra-file=F:\xampp\mysql\bin\my.ini
150602 14:39:21 [ERROR] Can't find messagefile '\xampp\mysql\share\english\errmsg.sys'
150602 14:39:21 [Warning] Can't create test file \xampp\mysql\data\MY-PC.lower-test
150602 14:39:21 [Warning] Can't create test file \xampp\mysql\data\MY-PC.lower-test
f:\xampp\mysql\bin\mysqld.exe: Can't change dir to '\xampp\mysql\data\' (Errcode: 2)
150602 14:39:21 [ERROR] Aborting
Open a command prompt - press Win key + R and type in cmd.
In the command prompt type in F:\xampp\mysql\bin\mysqld.exe and press Enter. (note it is mysqld with a d in the end)
What do you see? There should be an error, possibly regarding your config file.
EDIT:
Try using:
F:\xampp\mysql\bin\mysqld.exe --defaults-extra-file=F:\path\to\config
I'm new to the forums here but I hope to become more active as I've recently purchased a dedicated server and I'm running Fedora off of it so it's a constant learning process, I'm fairly average at BASH, but I know enough to make my way around, I'm a software developer to trade more than a network techi. Which leads me to my initial problem, I'm having an issue starting my MySQL daemon after rebooting my dedi, I have no clue why it's suddenly doing this, I'm running PHPMyAdmin from the server and also issuing certain commands through the CLI for MySQL, but after rebooting I'm getting this error everytime I try to start the instance of the daemon:
[root#ks23085 ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root#ks23085 ~]# systemctl mysqld start
Unknown operation mysqld
[root#ks23085 ~]# systemctl start mysqld
Failed to issue method call: Unit name mysqld is not valid.
[root#ks23085 ~]# systemctl start mysqld.service
[root#ks23085 ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/path/to/mysql.sock' (2)
It's completely bizarre as it was working perfectly before I rebooted it, I didn't update it or change the install, the only thing that I did do was install postfix, but I don't see why that would cause any issues with MySQL :S
I really need a hand on this one, I've tried several solutions from google with no results whatsoever. Thanks in advance guys.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Update 1:
Okay, so I found the directory that mysqld is held, it was '/usr/libexec/mysqld', I typed './mysqld start' in this directory and it specifies this output:
120729 1:49:09 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release. Please use '--slow-query-log'/'--slow-query-log-file' instead.
120729 1:49:09 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release. Please use '--slow-query-log'/'--slow-query-log-file' instead.
120729 1:49:09 [Warning] Can't create test file /run/mysql/ks23085.lower-test
120729 1:49:09 [Warning] Can't create test file /run/mysql/ks23085.lower-test
./mysqld: Can't change dir to '/run/mysql/' (Errcode: 2)
120729 1:49:09 [ERROR] Aborting
120729 1:49:09 [Note] ./mysqld: Shutdown complete
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Update 2:
I managed to get passed the directory issue by creating the 'mysql' directory in 'run/' with all my old databases, but now I seem to be getting an error that doesn't seem to be as easy to fix :/
Here's the output:
120729 2:15:59 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release. Please use '--slow-query-log'/'--slow-query-log-file' instead.
120729 2:15:59 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release. Please use '--slow-query-log'/'--slow-query-log-file' instead.
120729 2:15:59 [Warning] Can't create test file /run/mysql/ks23085.lower-test
120729 2:15:59 [Warning] Can't create test file /run/mysql/ks23085.lower-test
120729 2:15:59 [Note] Plugin 'FEDERATED' is disabled.
120729 2:15:59 [Note] Plugin 'InnoDB' is disabled.
mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
120729 2:15:59 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
120729 2:15:59 [ERROR] mysqld: unknown option '--skip-locking'
120729 2:15:59 [ERROR] Aborting
120729 2:15:59 [Note] mysqld: Shutdown complete
The official doc states that there's 2 possible reasons for this error:
You don't have permissions to access the directory /var/lib/mysql/whatever.sock because mysql is the owner of the folder
or
/path/whatever.sock doesn't exist.
Execute the following to find your socket:
mysqladmin variables | grep socket
Added to configuration file as suggested:
You can try this though [Linux specific, but what other operating
systems are there?] Go to /etc/my.cnf and change/add the lines:
[mysqld]
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock
2) Don't forget to check your permissions!