MySQL NOFILE limits on WSL2 - mysql

I am running MySQL on WSL2 for Windows. At WSL2 startup, MySQL does not start and I get the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I then run this command to get it going:
sudo service mysql start
And get the following output:
* Starting MySQL database server mysqld
su: warning: cannot change directory to /nonexistent: No such file or directory
[ OK ]
When I check my MySQL error logs, I see this error regarding max_open_files and table_open_cache:
2022-07-28T08:36:34.074107Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
2022-07-28T08:36:34.074111Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
My understanding is I need to edit my /lib/systemd/system/mysql.service file to change this, but when I check that file I see that LimitNOFILE is already set to 10000
# MySQL systemd service file
[Unit]
Description=MySQL Community Server
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
User=mysql
Group=mysql
PIDFile=/run/mysqld/mysqld.pid
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/sbin/mysqld
TimeoutSec=infinity
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755
LimitNOFILE=10000
# Set enviroment variable MYSQLD_PARENT_PID. This is required for restart.
Environment=MYSQLD_PARENT_PID=1
It's almost as if that setting get's ignored at service startup? Does anyone know where the right place is to set it if this isn't?

You need to check information in /etc/security/limits.conf
You can add something like (assuming you run mysqld as mysql user)
mysql hard nofile 10000
mysql soft nofile 8192
and in my.cnf
[mysqld]
open_files_limit = 10000
table_open_cache=4096
then logout, login and restart mysql

Related

Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)

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

MySQL warnings about max_open_files and table_open_cache

I have a MySQL 5.7 server on Ubuntu 18. When the server starts it writes the following warnings in the error.log:
[Warning] Changed limits: max_open_files: 5000 (requested 7500)
[Warning] Changed limits: table_open_cache: 1745 (requested 2000)
Can somebody explain what is causing these warnings (and what I can do to make them go away)?
Answering my own question. The limit for max open files is defined in the systemd script /lib/systemd/system/mysql.service:
# MySQL systemd service file
[Unit]
Description=MySQL Community Server
After=network.target
....
LimitNOFILE=5000
Increasing the value of LimitNOFILE to 7500 solved both warnings.

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

Percona XtraDB Cluster 5.6 does not start

All the good days. I want to run for test purposes Percona XtraDb Cluster on ubuntu 14.04. The basis here took these two articles
https://habrahabr.ru/post/152969/
https://www.percona.com/doc/percona-xtradb-cluster/5.6/manual/bootstrap.html
I came instead
Ну и в завершение, перезапускаем демона:
The daemon does not start
$ sudo /etc/init.d/mysql start
* Starting MySQL (Percona XtraDB Cluster) database server mysqld
* The server quit without updating PID file (/var/lib/mysql/vagrant-ubuntu-trusty-64.pid).
...fail!
The logs several errors. Error one:
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
Sure I ran mysql_upgrade, but it does not work
$ sudo mysql_upgrade
Looking for 'mysql' as: mysql Looking for 'mysqlcheck' as: mysqlcheck
FATAL ERROR: Upgrade failed
Error two:
160502 14:56:26 [ERROR] Plugin 'InnoDB' init function returned error.
160502 14:56:26 [ERROR] Plugin 'InnoDB' registration as a STORAGE
ENGINE failed. 160502 14:56:26 [ERROR] Unknown/unsupported storage
engine: InnoDB 160502 14:56:26 [ERROR] Aborting
All are advised to remove all of the folders / var / lib / mysql and supposedly starts. But I deleted and nothing worked.
My file my.cnf
[mysqld_safe]
# wsrep_urls=gcomm://192.168.33.101:3400,gcomm://192.168.33.102:3400,gcomm://
#wsrep_urls=gcomm://192.168.33.101:3400,gcomm://
[mysqld]
innodb_log_file_size=256M
wsrep_cluster_address=gcomm://192.168.33.101
port=3306
socket=/var/run/mysqld/mysqld.sock
datadir=/var/lib/mysql
basedir=/usr
user=mysql
log_error=/var/log/mysql.err
binlog_format=ROW
default_storage_engine=InnoDB
wsrep_provider=/usr/lib/libgalera_smm.so
wsrep_sst_receive_address=192.168.33.101:3500
wsrep_node_incoming_address=192.168.33.101
wsrep_slave_threads=2
wsrep_cluster_name=cluster0
wsrep_provider_options="gmcast.listen_addr=tcp://192.168.33.101:3400;"
wsrep_sst_method=xtrabackup
wsrep_sst_auth=backup:password
wsrep_node_name=node0
innodb_locks_unsafe_for_binlog=1
innodb_autoinc_lock_mode=2
innodb_buffer_pool_size=5000M
innodb_log_file_size=256M
innodb_log_buffer_size=4M
[client]
port=3306
socket=/var/run/mysqld/mysqld.sock
Actually the question: how to start? If there is anyone working configuration, then please share.
For the record:
Percona is amazing, but highly undocumented.
When it comes to configuring it, ive learned less is better.
important parts:
server-id required
these may be braking it, in my experience.
wsrep_sst_receive_address=192.168.33.101:3500
wsrep_node_incoming_address=192.168.33.101
Config from my cluster:
[mysqld]
server-id=18
datadir=/var/lib/mysql
wsrep_provider=/usr/lib/libgalera_smm.so
# Cluster connection URL -|-node0, -|-node1, -|-node2 -|-node3 -|-node4 -|-node5 -|-node6 -|-node7 -|-node8
wsrep_cluster_address=gcomm://192.168.1.18,192.168.1.19,192.168.1.20 #removed some
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_sst_method=rsync
wsrep_sst_auth="root:password"
wsrep_cluster_name=grapes
innodb_buffer_pool_size=5140
innodb_buffer_pool_instances=4
innodb_flush_log_at_trx_commit=0
query_cache_size=0

Missing mysql.sock file. phpMyAdmin - Fedora 17

I run Fedora 17 with "Webadmin". So I tried to use webadmin option to update upload maximum size to my MySQL database. Now, I not able to restart mysqld. I have no GUI, so when run systemctl status mysqld.service I gives me this message:
[root#localhost ~]# systemctl status mysqld.service
mysqld.service - MySQL database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
Active: failed (Result: exit-code) since Mon, 30 Jul 2012 15:08:26 -0400; 6min ago
Process: 3560 ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID (code=exited, status=1/FAILURE)
Process: 3559 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
Process: 3542 ExecStartPre=/usr/libexec/mysqld-prepare-db-dir (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/mysqld.service
Jul 30 15:08:23 localhost mysqld_safe[3559]: 120730 15:08:23 mysqld_safe Logging to '/var/log/mysqld.log'.
Jul 30 15:08:23 localhost mysqld_safe[3559]: 120730 15:08:23 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
or when I try to access my phpmyadmin screen i see this message:
phpMyAdmin - Error
#2002 - Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
The server is not responding (or the local server's socket is not correctly configured).
When I run in terminal locate mysql.sock it shows the correct path /var/lib/mysql/mysql.sock.
But when I run this command ls /var/lib/mysql, I not able to locate this file.
Please help.
After punching my monitor and kicking my server I was able to find a fix. Not sure how safe or good at is, but it works to me.
In terminal open up your my.cnf file # nano /etc/my.cnf
Delete or just comment all existing settings with '#', then just paste this code that I found on http://blog.mclaughlinsoftware.com/2011/12/07/fixing-my-cnf-on-fedora/
[mysqld]
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
# Default directory.
datadir=/var/lib/mysql
# The TCP/IP Port the MySQL Server listens on.
port=3306
# The Linux Socket the MySQL Server uses when not using a listener.
# socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# The default storage engine that will be used when creating new tables.
default-storage-engine=INNODB
# Set the SQL mode to strict.
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# Set the maximum number of connections.
max_connections=100
# Set the number of open tables for all threads.
table_cache=256
# Set the maximum size for internal (in-memory) temporary tables.
tmp_table_size=26M
# Set how many threads should be kept in a cache for reuse.
thread_cache_size=8
# MyISAM configuration.
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=52M
key_buffer_size=36M
read_rnd_buffer_size=256K
sort_buffer_size=256K
# InnoDB configuration.
innodb_data_home_dir=/var/lib/mysql
innodb_additional_mem_pool_size=2M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1M
innodb_buffer_pool_size=25M
innodb_log_file_size=5M
innodb_thread_concurrency=8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Open for any comments or suggestions.
Thank you.