Running two instances of mysql - mysql

I'm trying to run two instances of MySQL on the same machine and setup my.cnf file as the following:
[mysqld1]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3307
datadir = /var/lib/mysql
[mysqld2]
user = mysql
pid-file = /var/run/mysqld/mysqld2.pid
socket = /var/run/mysqld/mysqld2.sock
port = 3308
datadir = /var/lib/mysql2
When I execute mysqld_multi start command, it arises the following error:
Installing new database in /var/lib/mysql2
2016-10-06 17:47:23 [WARNING] mysql_install_db is deprecated. Please
consider switching to mysqld --initialize 2016-10-06 17:47:23 [ERROR]
Can't locate the server executable (mysqld).
FATAL ERROR: Tried to start mysqld under group [mysqld2], but no data
directory was found or could be created. data directory used:
/var/lib/mysql2
How can I solve this?
Note: MySQL is running on Ubuntu 16.0.4 and MySQL 5.7

I know the one question.
2016-10-06 17:47:23 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2016-10-06 17:47:23 [ERROR] Can't locate the server executable (mysqld).
Please vim the line 343 to 344&345 in the file /use/bin/mysqld_multi
343 #$install_cmd="/usr/bin/mysql_install_db ";
344 $install_cmd="/usr/bin/mysqld ";
345 $install_cmd.="--initialize ";
346 $install_cmd.="--user=mysql ";
347 $install_cmd.="--datadir=$datadir";

Related

Failed to find valid data directory. MySQL generic binary installion

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

Why mysqld_multi can't start mysql?

In my my.cnf, I write:
[mysqld_multi]
mysqld = /usr/local/Cellar/mysql/5.7.11/bin/mysqld_safe
mysqladmin = /usr/local/Cellar/mysql/5.7.11/bin/mysqladmin
user = root
password =
[mysqld1]
pid-file = /usr/local/etc/mysql/mysqld.pid
socket = /usr/local/etc/mysql/mysqld.sock
port = 3306
datadir = /usr/local/var/mysql
log-bin=mysql-bin
server-id=1
[mysqld2]
pid-file = /usr/local/etc/mysql/mysqld1.pid
socket = /usr/local/etc/mysql/mysqld1.sock
port = 3307
datadir = /usr/local/var/mysql1
server-id=2
language=/usr/local/Cellar/mysql/5.7.11/share/mysql/english
user=mysql
Then I execute mysqld_multi start 2, and I get the error info:
Installing new database in /usr/local/var/mysql1
2016-09-19 19:37:16 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-09-19 19:37:16 [ERROR] Can't locate the language directory.
FATAL ERROR: Tried to start mysqld under group [mysqld2],
but no data directory was found or could be created.
data directory used: /usr/local/var/mysql1
I can't start the mysql process, so what's the problem? It seems the directory /usr/local/var/mysql1 has some problems, but the directory exists, it's confused.
It seems like mysqld_multi wasn't fixed to use mysqld --initialize.
You will have to run mysqld --initialize along with all directory related options in my.cnf for that server.
(from comment)
You can also fix the mysqld_multi script following the instructions in Running two instances of mysql.

Debian Plesk Server: MySQL doesn't start

I have a little Problem with a MySQL Server running on a Debian Server managed by Plesk. If I try to start the MySQL Server the following message is logged at MySQL_error.log:
150518 02:54:42 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
150518 02:55:15 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150518 2:55:15 [Warning] Using unique option prefix w instead of wait_timeout is deprecated and will be removed in a future release. Please use the full name instead.
150518 2:55:15 [ERROR] /usr/sbin/mysqld: option '--wait_timeout' requires an argument
150518 2:55:15 [ERROR] Aborting
150518 02:55:15 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
But I never modified my config file and I did never set a --wait_timeout argument.
Can someone help me out?
Pay attention for this string:
"Using unique option prefix w instead of wait_timeout is deprecated"
Check that there is no "w" command argument or option in my.cnf.

Mysql: Can´t start Server debian wheezy

Everytime i try to start my mysql service i get the same error
Error message:
150130 15:56:31 [ERROR] Can't start server: Bind on TCP/IP port: Cannot assign requested address
150130 15:56:31 [ERROR] Do you already have another mysqld server running on port: 3305 ?
150130 15:56:31 [ERROR] Aborting
My Error log is empty
Conf file snippet:
[client]
port = 3305
socket = /var/run/mysqld/mysqld.sock
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3305
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
Sorry for my bad english
Complete Conf file
Looks like your port(3305) is occupied by another process.. you can :
1) switch to different port
2) kill/modify the process holding this port
(look it up using:
lsof -i :3305
)
in addition, this could be the cause of it (as one stated in this post) :
Change bind-address to 127.0.0.1 instead of localhost
Skipping network worked for me :
# echo "skip-networking" >> /etc/mysql/my.cnf
Then start mysql again.

start using pre-compiled mysql, but get: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I knew the question I am asking is somewhat alike with other guys, but my case is a little different:
I did not install mysql-server using yum, nor did I install it with rpm or compile-makeinstall.
I simply downloaded the compressed precompiled binary from the official website:
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
So, there is no /etc/init.d/mysqld, the "service mysqld start/stop/restart" could not work.
I unarchived it and initialized the DB with:
./scripts/mysql_install_db
then start it with:
./bin/mysqld_safe &
everything work fine till now, but when I tried to connect it using mysql, it prompted:
# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
The data directory was changed to:
drw-rw-rw- 4 mysql mysql 4096 Jan 3 14:03 mysql
The following stop command also could not work:
# mysqladmin shutdown
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
The mysqld_safe process and mysqld process are all working fine:
# ps -ef | grep mysqld
root 10977 5685 0 14:03 pts/2 00:00:00 /bin/sh ./bin/mysqld_safe
mysql 11154 10977 0 14:03 pts/2 00:00:00 /root/mysql-5.1.73-linux-x86_64-glibc23/bin/mysqld
--basedir=/root/mysql-5.1.73-linux-x86_64-glibc23
--datadir=/var/lib/mysql --user=mysql
--log-error=/var/log/mysqld.log
--pid-file=/var/run/mysqld/mysqld.pid
--socket=/var/lib/mysql/mysql.sock
root 11650 5685 0 14:26 pts/2 00:00:00 grep mysqld
some config information in the /etc/my.cnf is :
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
# ps -ef | grep mysqld
root 10977 5685 0 14:03 pts/2 00:00:00 /bin/sh ./bin/mysqld_safe
mysql 11154 10977 0 14:03 pts/2 00:00:00 /root/mysql-5.1.73-linux-x86_64-glibc23/bin/mysqld
--basedir=/root/mysql-5.1.73-linux-x86_64-glibc23
--datadir=/var/lib/mysql --user=mysql
--log-error=/var/log/mysqld.log
--pid-file=/var/run/mysqld/mysqld.pid
--socket=/var/lib/mysql/mysql.sock
your socket is at /var/lib/mysql/mysql.sock
guess you are using /usr/bin/mysql
to connect to mysql, you can update /etc/my.cnf, set socket=/var/lib/mysql/mysql.sock for [mysql] section
[mysql]
socket=/var/lib/mysql/mysql.sock
To fix mysqladmin you need to add the section [mysqladmin] also
[mysqladmin]
socket=/var/lib/mysql/mysql.sock
Alternatively you can add [client], it should work for both mysql and mysqladmin
[client]
socket=/var/lib/mysql/mysql.sock
Don't you need to do a
mysql.server start