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
Related
I followed a guide to setup docker and mysql (which i can no longer find) and everything went as expected. However i had to reinstall my OS, and now using the same commands doesn't do what i expect.
when creating a new container, then running "docker logs <container_name>", i expect to see a long string of log info, among which is a one time randomly generated password, which i can then use to change to a more memorable password.
However, i only get a short paragraph of logs with no password.
I even copied commands line-for-line from an official mysql guide that explicitly states should show me a password, but doesn't.
Strangely, i realised docker needed an update, ran the update and found that running the log command now shows the password as expect! But when i tried it again on another container, the original problem returned. I haven't been able to recreate that success since.
I feel like i'm out of options for troubleshooting.
Here is all the code i ran, from installing docker to printing the log file.
#docker setup
sudo systemctl enable docker.service #start docker on startup
sudo systemctl start docker.service #start docker now
sudo docker pull mysql/mysql-server:latest
#create volumes
sudo docker volume create mysql-config
sudo docker volume create mysql-data
#container setup
sudo docker run --name master32-mysql -dp 3306:3306 -v mysql-data:/var/lib/mysql mysql/mysql-server:latest
sudo docker logs master32-mysql
Here are the logs i get after running the last command:
[Entrypoint] MySQL Docker Image 8.0.28-1.2.7-server
[Entrypoint] Starting MySQL 8.0.28-1.2.7-server
2022-01-27T00:52:41.963514Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 1
2022-01-27T00:52:41.969879Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-27T00:52:42.066204Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-27T00:52:42.219166Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-01-27T00:52:42.219204Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-01-27T00:52:42.233405Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-01-27T00:52:42.233414Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
Can anyone figure out why this isn't showing me a password? I'm aware that this command only shows the password one time, but i'm having this problem with every new container i make.
SOLUTION:
The main problem was that i was expecting every new container to generate it's own password, whithout realising that the password is stored in the volume which is linked to the container. To get a new password, i needed to create new volumes and link the new container with that instead.
I also needed to add '-e MYSQL_RANDOM_ROOT_PASSWORD=1' to the 'docker run' command.
You haven't specified '-e MYSQL_RANDOM_ROOT_PASSWORD=1' on startup (docker run).
ref: entrypoint.
ref: docker hub docs
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
Another macOS upgrade + another MySQL upgrade = another set of problems.
I can't seem to get MySQL 8.0.18 to run as a homebrew service on macOS 10.15 Catalina. Please show me the error of my ways.
Here's what I did:
brew install mysql
brew pin mysql
touch /tmp/mysql.sock
mysql.server start
unset TMPDIR
mysql_secure_installation
mysql.server stop
sudo brew services start mysql
Here's what I expected:
MySQL to run merrily along as a homebrew service as user root.
Here's what happened:
MySQL falls right over and dies, leaving a cryptic last statement in /usr/local/var/mysql/[host.domain.com].err:
"[ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!"
Additional information:
MySQL runs fine through subsequent reboots so long as I launch it manually:
sudo reboot now
ssh [servername.domain.com]
touch /tmp/mysql.sock
mysql.server start
Here's the /usr/local/var/mysql/[servername.domain.com].err file contents:
2019-10-20T18:02:14.6NZ mysqld_safe Logging to '/usr/local/var/mysql/moriarty.farces.com.err'.
2019-10-20T18:02:14.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2019-10-20T18:02:14.670494Z 0 [System] [MY-010116] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld (mysqld 8.0.18) starting as process 557
2019-10-20T18:02:14.685511Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2019-10-20T18:02:15.617696Z 0 [System] [MY-010229] [Server] Starting crash recovery...
2019-10-20T18:02:15.626461Z 0 [System] [MY-010232] [Server] Crash recovery finished.
2019-10-20T18:02:15.795626Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-10-20T18:02:15.833541Z 0 [System] [MY-010931] [Server] /usr/local/Cellar/mysql/8.0.18/bin/mysqld: ready for connections. Version: '8.0.18' socket: '/tmp/mysql.sock' port: 3306 Homebrew.
2019-10-20T18:02:15.993739Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/tmp/mysqlx.sock' bind-address: '127.0.0.1' port: 33060
After a reboot, when I try to run MySQL as a Homebrew service:
sudo reboot now
ssh [servername.domain.com]
sudo brew services start mysql
MySQL fails with the following error recorded in the /usr/local/var/mysql/[servername.domain.com].err file:
2019-10-20T18:44:13.780394Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2019-10-20T18:44:13.780503Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-10-20T18:44:13.780727Z 0 [System] [MY-010910] [Server] /usr/local/opt/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.18) Homebrew.
2019-10-20T18:44:13.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/moriarty.farces.com.pid ended
Never use sudo with command brew. It will ruin the ownership of related files. Running brew as root is not supported. (I'm talking about brew, not mysqld)
Quote from Homebrew doc
tl;dr Sudo is dangerous, and you installed TextMate.app without sudo anyway.
Homebrew refuses to work using sudo.
Warnings from the source code of brew
check-run-command-as-root() {
...
odie <<EOS
Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
EOS
}
Solutions
Disable the service and remove the launchdaemon.
# stop and unload the launchdaemon
sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
# remove the lauchdaemon file
sudo rm -f /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
sudo rm -f /tmp/mysql.sock /tmp/mysqlx.sock
Fix ownership of homebrew related files
# For x86 Mac
sudo chown -R "$(whoami):admin" /usr/local/*
# For M1 Mac
sudo chown -R "$(whoami):admin" /opt/homebrew/*
# it will take some time
Re-enable the MySQL service.
# DO NOT USE "sudo brew"
brew services start mysql
Update:
Seems some of you are not familiar with Homebrew. I'll explain how Homebrew manages services here.
mysqld listens at port 3306 by default, which is not a privileged port. So there's no need to start mysqld with root. systemd starts mysqld with root on Linux, but macOS is not Linux.
Homebrew manages services with the help of launchd, which is kind of a systemd alternative on macOS. launchd starts a foreground process and manages it for you, just like what systemd does.
brew services start/stop mysql will suffice your need. It creates a launchd file ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist, starts mysqld with it (run by current user).
/usr/local/mysql/support-files/mysql.server is a shell script brought by MySQL to help you start mysqld. Using it directly is not recommended unless you build MySQL from source outside Homebrew. If you're using Homebrew, just stick with brew services. Or say it in another way, if you're using Homebrew, you should do things in the Homebrew way.
MySQL refuses to start on Catalina because elevated privileges are required to run it.
You need to locate your MySQL bin directory first:
which mysqld
The result you get should be similar to /usr/local/mysql/bin/mysql.
The support-files directory contains the required scripts needed to start-up MySQL, and is located in the same directory where the bin directory is located. In the above example, the support files directory will be /usr/local/mysql/support-files/.
Start the MySQL service with administrative privileges as follows:
sudo /usr/local/mysql/support-files/mysql.server start
N.B: In case the output from the first command you run is different from the one above, adjust the support-files directory accordingly as explained above.
Oh geez, he says, shaking his head...
This was a case of RTFM, and I didn't. Here's the applicable page from the MySQL 8.0 Reference manual. And here's the magic juju:
Add user=root to the [mysqld] section of the /usr/local/etc/my.cnf file, like so:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
user=root
I just encountered the same issue after upgrading to Catalina.
If I started MySQL server from system preferences it would just start and stop itself. The solution for me was:
sudo /usr/local/mysql-8.0.17-macos10.14-x86_64/support-files/mysql.server start
instead of: /usr/local/mysql/support-files/mysql.server start
I've encountered a lot of problems with Catalina. Now I can't start/stop mysql server from system preferences, only from terminal.
It's my first post so I hope this helps, I only registered to answer you since you're the only one I found with the same question.
I solved like this:
Remove MySQL completely Watching: https://gist.github.com/vitorbritto/0555879fe4414d18569d
Install MySQL with Download do MySQL community server
https://dev.mysql.com/downloads/mysql/
And Done! Successfully!
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
I've been running MySQL Ver 14.14 Distrib 5.6.10, for osx10.6 (x86_64) for a while with no issues. I had to hard restart my laptop tonight, and a while after it started, i tried to access a dev database. I got the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
here are the commands and responses:
$ which mysql
#=> mysql: aliased to nocorrect mysql
$ unset TMPDIR
$ mysql_install_db
#=> FATAL ERROR: Could not find ./bin/my_print_defaults
$ sudo /usr/local/mysql/support-files/mysql.server start
#=> ERROR! The server quit without updating PID file (/usr/local/mysql/whoamis-MacBook-Pro.local.pid).
$ mysqld
#=> 2013-10-19 00:11:08 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-10-19 00:11:08 5029 [Warning] Can't create test file /usr/local/var/mysql/whoamis-MacBook-Pro.lower-test
2013-10-19 00:11:08 5029 [Warning] Can't create test file /usr/local/var/mysql/whoamis-MacBook-Pro.lower-test
mysqld: Can't change dir to '/usr/local/var/mysql/' (Errcode: 2 - No such file or directory)
2013-10-19 00:11:08 5029 [ERROR] Aborting
2013-10-19 00:11:08 5029 [Note] Binlog end
2013-10-19 00:11:08 5029 [Note] mysqld: Shutdown complete
$ usr/local/Cellar/mysql
sure enough, there was a mysql installation here, too. So there's one in /usr/local/mysql and there's one in /usr/local/Cellar/mysql, but there's not one in /usr/local/var which is where mysqld, at least, seems to be looking. It's worth noting that the system preferences tool as well as mySQL Workbench server tool doesn't successfully start the server, either. Any idea where to proceed from here?
As per this site
$ sudo mv my.cnf old_my.cnf
$ Password:
$ sudo /usr/local/mysql/support-files/mysql.server start
Starting MySQL
SUCCESS!
It works! However, it's good to note that this isn't perhaps the 'best' way - as Brad Quellhorst notes in the comments:
The better advice would be "Remove anything you recently added to my.cnf and remove the file as a last resort" Unless you already have a bare-defaults my.cnf, by removing it you're destroying any configuration options in favor of defaults, which among other things, are rather insecure. Binding MySQL to all open IPs and removing any caching, replication, and data information is not the solution to a typo'd configuration statement.