Cannot start Mysql 5.7 on cent 0s 6.10 - mysql

I am trying to setup MySql 5.7 on CentOS 6.10. I've installed MySQL but when I try to run sudo service mysqld start, it is not starting. The error is
2018-11-05T17:14:57.569757Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-05T17:14:57.573328Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 10355 ...
2018-11-05T17:14:57.575610Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2018-11-05T17:14:57.575652Z 0 [ERROR] Aborting
2018-11-05T17:14:57.575671Z 0 [Note] Binlog end
2018-11-05T17:14:57.575741Z 0 [Note] mysqld: Shutdown complete
I guess it is something to do with selecting the user type as root but I'm not able to figure out what to do. Can someone help?Thanks in advance

It looks like mysqld is configured to run as the root user right now, which is not a recommended way for it to run--hence the hard warnings forcing you to change your configuration. You should instead run as the mysql user that was created for you when you installed the package.
You can see the user mysqld is set up to run under by looking in the [mysqld] section of my.cnf. It seems most likely you have user=root, or the command line flag of --user=root is being applied.
Best practice would be to configure it to use the non-privileged mysql user instead.
Relevant documentation:
The How to Run MySQL as a Normal User documentation page indicates that:
the MySQL server mysqld should be started by the local mysql operating system user. Starting by another operating system user is not supported by the init scripts that are included as part of the installation.
MariaDB (a fork of MySQL) provides a documentation page called Running mysqld as root which indicates:
MariaDB should never normally be run as the system's root user (this is unrelated to the MariaDB root user). If it is, any user with the FILE privilege can create or modify any files on the server as root.
MariaDB will normally return the error Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root! if you attempt to run mysqld as root. If you need to override this restriction for some reason, start mysqld with the user=root option.
Better practice, and the default in most situations, is to use a separate user, exclusively used for MariaDB. In most distributions, this user is called mysql.

Related

MAMP Pro and MySQL having Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root

After updating to macOS Catalina I’m not able to run MySQL with MAMP Pro.
I get an error. Here from mysql_error.log
2019-10-09T10:53:16.6NZ mysqld_safe Logging to '/Applications/MAMP/logs/mysql_error.log'.
2019-10-09T10:53:16.6NZ mysqld_safe Starting mysqld daemon with databases from /Library/Application Support/appsolute/MAMP PRO/db/mysql57
2019-10-09T10:53:16.917470Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2019-10-09T10:53:16.919285Z 0 [Note] /Applications/MAMP/Library/bin/mysqld (mysqld 5.7.26) starting as process 3320 ...
2019-10-09T10:53:16.932570Z 0 [Warning] Setting lower_case_table_names=2 because file system for /Library/Application Support/appsolute/MAMP PRO/db/mysql57/ is case insensitive
2019-10-09T10:53:16.932669Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2019-10-09T10:53:16.932697Z 0 [ERROR] Aborting
2019-10-09T10:53:16.932751Z 0 [Note] Binlog end
2019-10-09T10:53:16.935298Z 0 [Note] /Applications/MAMP/Library/bin/mysqld: Shutdown complete
2019-10-09T10:53:16.6NZ mysqld_safe mysqld from pid file /Applications/MAMP/tmp/mysql/mysql.pid ended
I was searching the interenet and i’ve already tried a lot, but i can’t get it running.
Anyone experienced the same problem and could help?
Thx in advance!
I have a temporary fix, until the developers release a fix. I am using MAMP Pro; I don't know if the interface is the same in non-Pro. The temp fix:
Open MAMP Pro. Stop servers if they are running. Open the MySQL template from the menu: File > Edit Template > MySQL (mysql.cnf) > 5.7.26
Scroll down or find [client]. Beneath [client] add the following line:
user = root
Scroll down or find [mysqld]. Beneath [mysqld] add the following line:
user = root
Start servers.
This worked for me. Hope it helps you.
I had the same problem after installing Catalina on my Mac. First I have tried solution of Les Brown. Did not completely work for me. I got another error:
[Note] Access denied for user 'root'#'localhost' (using password: NO)
After some reading I saw a video on youtube (https://www.youtube.com/watch?v=LKE1G4sinBM) which lets you add the keyword skip-grant-tables in the section mysqld of the MySql template of MAMP-PRO. That let mysql working, but is not the best idea to have forever in your template file. If your try to add the line, do not forget to remove it also!
Last but not least I got the hint of MAMP-Pro-support to make a symbolic link to the mysql.stock. So I executed in Terminal (the '$' is the prompt of terminal).
$ sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
Password:...
$
Now everything is working fine.
The answer from Les Brown helped me. I have one addition that may apply to you and others.
If MAMP (PRO) is accessing any directories in Documents or iCloud Drive, Catalina requires the user to approve MAMP's and/or MYSQL's access to that directory.
For instance, on one of my MAMP PRO servers, I run an ETL (using cron) that downloads csv files from a website, then loads data from each downloaded csv into specified MySQL tables in my testing database. The script wouldn't work, however, because MySQL did not have permission to access the downloaded csv files from the Documents directory. I had to run manually my ETL script from the command line. At that point, a MacOS modal popped up directing me to grant permission for MySQL to access Documents. Once I granted that permission, the ETL scripts began working.

Resetting MySQL root password giving error when running init-file

I know there are countless questions and posts about this, but I'm getting an error when trying to start the MySQL Server and I don't know how to solve it.
So to explain I cannot access my database so I tried to reset the password of the root user. I've followed this guide however I've had no luck. First I had issues with permissions on my machine and now I'm getting this error:
1105 Bootstrap file error, return code (0). Nearest query: ''
Technically the MySQL Server is starting, however the init-file is not being run, and so my password is not being reset.
Command I am running is this:
mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 5.7\\my.ini" --init-file=C:\\mysql-init.txt --console
Contents of mysql-init.txt
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password';
The following is the part of the log where the error is shown:
[Note] Execution of init_file 'C:\\mysql-init.txt' started.
[ERROR] 1105 Bootstrap file error, return code (0). Nearest query: ''
[Note] Execution of init_file 'C:\\mysql-init.txt' ended.
[Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: ready for connections.
MySQL Version: 5.7
OS: Windows 10
Actually you can pass the command:
--init-file=C:\\mysql-init.txt
as a parameter to start the MySQL service from its general tab.
(Source)
Had two errors with MySQL 5.7.24
1.) The script file must be in a separate folder (not mysql installation folder or data directory)
and that folder must get "secure-file-privileges"
2.) The error above was raised for the script did not end with a ';'
Succeeded then with command line statement as
mysqld --datadir=D:\ProgramData\mysql\data --init-file=D:\ProgramData\mysql\reset\reset.sql --secure-file-priv=D:\ProgramData\mysql\reset --console
and SQL-script file 'reset.sql' as
alter user 'root'#'localhost' identified by 'root_pwd';
For me, on Ubuntu, problem was init file was not owned by mysql user.
chown mysql:mysql /tmp/reset_mysql_pswd.sql
sudo mysqld --init-file=/var/lib/mysql/reset_mysql_pswd.sql
# ^C or kill -9 <mysqld pid>
systemctl stop mysql.service
systemctl start mysql.service
Even when the folder containing the init file and the init file itself had permissions 777 (which is a bad idea), I still get:
2020-04-10T23:14:48.030719Z 0 [Note] Execution of init_file '/tmp/reset_mysql_pswd.sql' started.
2020-04-10T23:14:48.030764Z 0 [ERROR] mysqld: File '/tmp/reset_mysql_pswd.sql' not found (Errcode: 13 - Permission denied)
2020-04-10T23:14:48.030772Z 0 [ERROR] Aborting

MacOS Can't start MySQL Server

I have MacOS Sierra. I have installed MySQL Server which has been working, however, after a reboot of the Mac Book, I cannot start the MySQL Server.
I have tried changing the port from 3306 to 3307 in the my.cnf file.
Question
I would appreciate any help on how to start the MySQL Server, and also have it so it starts automatically on MacOS Boot up.
(I am new to Mac, so apologies if this is a basic question).
UPDATE
Looking for error logs, I can't find anything with todays (2/2/2017) timestamp.
Nothing in the data dir:
No files with "mysql" have been modified since I've tried to start the MySQL Server (2/2/2017 after 09:00).
I suggest using Terminal commands.
Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start
Stop MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
Restart MySQL
sudo /usr/local/mysql/support-files/mysql.server restart
In my case, I had inadvertently transferred ownership of entire /usr/local directory to myself, which resulted in snatching-away of write permission of /usr/local/mysql-5.7.20-macos10.12-x86_64/data directory from the daemon user called "_mysql".
Restoring the ownership fixed the issue.
After a discussion with Richard, the following solves the issue:
my.cnf:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql-5.7.17-macos10.12-x86_64/data
tmpdir = /tmp
Essentially, although we'd added the relevant stanza's to the my.cnf file, we'd still missed the section heading. Adding the [mysqld] section allowed mysql to start.
After installing Mysql 8.0.12 on MacOS High Sierra, Mysql server would not start up. I tried several suggestions like removing mysql and reinstalling it, rebooting the computer and changing file permissions, all to no avail. I finally got it to work by removing /etc/my.cnf.
In my case, ownership of the msyql directory had somehow changed to admin:admin. I use ares suggestion to run mysqld from the terminal:
sudo /usr/local/mysql/support-files/mysql.server start
Which showed a permissions error writing to a msyql file.
I fixed with this command:
sudo chown -R _mysql:wheel /usr/local/mysql/data
from this post:
What user should own /usr/local/mysql on Mac?
In my case, First time, after installing Mysql, Mac needs a restart.
So restarting Mac, after installation, fixed the issue for me.
MacOS doesn't come with a my.cnf file. Default settings will suffice the needs for basic usage. Once we need to override them, it makes sense to have a custom configurations.
This solution works for me.
You have to open the activity monitor up and search for mysqld service. Once selected, just click the delete button located in the up left part and you will see the memory goes down. After that, you can verify your mysql server status from System Preferences and the service is up.
With this solution you don't have to restart your machine and get to work fast.
My problem was that due to an incorrect restart of my machine, a database was corrupted. According to their docs doing a forced InnoDB Recovery did the trick:
/etc/my.cnf
innodb_force_recovery = 2
My problem was that I installed MySQL a while ago with Homebrew (forgot I did) and then went the more manual route, so I think the two installs were fighting each other. I wiped my Mac of both with the help of this walkthrough: https://gist.github.com/vitorbritto/0555879fe4414d18569d
Note: Where it says to use subl - that's Sublime, use whatever editor you like.
I was able to get things to work with a fresh install after that.
I had this same issue on Monterey. Make sure you're selecting the correct download according to your processor architecture.
I ran into same problem with following .err log.
MacOS: Catalina 10.15.7.
MySQL version: 5.7.19.
2021-08-19T02:17:26.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2021-08-19T02:17:27.303813Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-19T02:17:27.318280Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-08-19T02:17:27.335112Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.19) starting as process 2828 ...
2021-08-19T02:17:27.421394Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2021-08-19T02:17:27.428986Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2021-08-19T02:17:27.429541Z 0 [ERROR] Aborting
2021-08-19T02:17:27.429688Z 0 [Note] Binlog end
2021-08-19T02:17:27.432786Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
And I found adding --user=root to Ares's answer will start mysql server successfully.
sudo /usr/local/mysql/support-files/mysql.server start --user=root
Ref.: MySQL Server Command User Options

The server quit without updating PID file '

I use the command:
/usr/local/Cellar/mysql/5.6.26/support-files/mysql.server start
to start the database and get the error info:
ERROR! The server quit without updating PID file(/usr/local/var/mysql/macbooks-MacBook-Pro.local.pid).
The local.err has the following information:
151103 20:43:37 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2015-11-03 20:43:37 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-03 20:43:37 0 [Note] /usr/local/Cellar/mysql/5.6.26/bin/mysqld (mysqld 5.6.26) starting as process 42772 ...
2015-11-03 20:43:37 42772 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2015-11-03 20:43:37 42772 [Note] Plugin 'FEDERATED' is disabled.
/usr/local/Cellar/mysql/5.6.26/bin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13 - Permission denied)
2015-11-03 20:43:37 42772 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
Your MySQL installation appears to be damaged. You have an error but the proposed resolution isn't likely to help:
/usr/local/Cellar/mysql/5.6.26/bin/mysqld: Can't find file: './mysql /plugin.frm'
(errno: 13 - Permission denied)
2015-11-03 20:43:37 42772 [ERROR] Can't open the mysql.plugin table.
Please run mysql_upgrade to create it.
As you see, MySQL cannot open a file, but not because it does not exist; rather because it has no rights to do so (error 13).
From the console, verify the status of the mysql/plugin.frm file in the 'mysql' directory. You'll need to find the MySQL data directory (mysql).
Supposing it's /usr/local/var/mysql/, you would do
ls -la /usr/local/var/mysql/ | more
(SPACE or ENTER to page the output) and see a row containing "plugin.frm".
If there is not, then running the mysql_upgrade command might fix things (but backup the mysql installation and data directory first! Just in case).
If there is, verify it has the same user and group as the other files. Chances are that the other files will be owned by Cellar/users and this, maybe, by root/wheel. As administrator (su), try running
chown Cellar:users ./mysql/plugin.frm
and this should fix the Errno 13, and possibly the PID trouble as well.
Failing everything else, reinstalling MySQL could be a solution. You'll install the same version 5.6.26, then verify the data directory and, if necessary, overwrite it with your backup, having care to preserve the new ownerships and permissions.
This trick isn't guaranteed to work between different MySQL versions and OSes, but on the same machine with the same MySQL version and OS it stands excellent chances.
You can also run a partial restore of only the databases you need (for example you can skip restoring the mysql tablespace where all users and permissions are. You'll lose them, but the data will still be accessible in the other databases).

Building MySQL as non-root and with another MySQL already running

I need to use a bioinformatics tool that uses MySQL. The tool is called SyMap. When I try to run SyMap, it tells me there's a MySQL server already running so I should either shut it down or point SyMap to another server. Since I work on an HPC that allows me limited permissions, I cannot shutdown the MySQL server. So I've been trying to build my own local MySQL server. With zero knowledge about MySQL, this has been frustrating.
I tried to follow this guide to build MySQL as a non-root user with the addition of the flag MYSQL_TCP_PORT=3307 to the cmake command to have the local server run on a different port than the original's (3306). Whenever I get to the step where I have to execute mysql_install_db, it says:
2015-10-31 20:52:02 [WARNING] mysql_install_db is deprecated. Please
consider switching to mysqld --initialize 2015-10-31 20:52:02 [ERROR]
Child process: /home/rajeha/software/mysql/bin/mysqldterminated
prematurely with errno= 32 2015-10-31 20:52:02 [ERROR] Failed to
execute /home/rajeha/software/mysql/bin/mysqld --bootstrap
--datadir=/home/rajeha/software/mysql/data --lc-messages-dir=/usr/share/mysql --lc-messages=en_US
-- server log begin -- 2015-11-01T01:52:02.964453Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead 2015-11-01T01:52:02.969334Z 0 [ERROR] Invalid old_passwords mode: 1.
Valid values are 2 and 0
2015-11-01T01:52:02.969376Z 0 [ERROR] Aborting
-- server log end --
I also tried to run the ./bin/mysqld --initialize --user=mysql command, but I still get the error that old_passwords is equal to 1.
If I try to run the server with mysql_safe, it says:
*./bin/mysqld_safe: line 130: /var/log/mysqld.log: Permission denied ./bin/mysqld_safe: line 164: /var/log/mysqld.log: Permission denied
151031 20:53:12 mysqld_safe mysqld from pid file
/home/rajeha/software/mysql/the.pid ended ./bin/mysqld_safe: line 130:
/var/log/mysqld.log: Permission denied*
This is because it's trying to access /var/log/ which I cannot write onto. I probably have to change the config file that tells mysql to access this directory, and that also specifies the value of old_passwrods, but I don't know where to find it.
I would appreciate your help.
Thanks.