I can't login my MySQL server. I got many solutions via the internet but not working any single solution.
The first thing is to ensure that MySQL server is up and running. This procedure is different for different distros, but you can try
$ sudo /etc/init.d/mysql start
to start
MySQL is not starting.
As suggested, your first step is to bang out the typical commands: service mysql status and journalctl -xe to see what errors are reported. The usual suspects are permissions on the mysql data folder typically located in/var/lib/mysql (permissions should be mysql:mysql) and also errors in my.cnf (/etc/mysql/my.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf for recent mariadb installs)
If your MySQL was previously running and now wont start, you might be dealing with table corruption. Get mysqlcheck running on it if this is the case. If you are going to attempt a database startup with innodb_force_recovery flag, make sure you have your data backed up prior to launching the database.
Let us know the output of these commands so we can further assist.
Is there any way to show actual i/o performed by a query in mysql
You can edit /etc/mysql/my.cnf to enable query logs by adding this to the end of this file:
[mysqld]
general_log=on
general_log_file=/var/log/mysql/query.log
Restart the mysql service and check logs by running:
tail -f /var/log/mysql/query.log
This answer was based here.
I'm attempting to script the creation of a machine image that includes MySQL with some seed data.
I'm looking for a way to start the MySQL database engine, run a .sql script to create the data, and then shutdown the engine. Is there a best way to do this?
It looks like I could use the --init-file argument of mysqld to launch mysql and run the script, but how would I cause the database engine to shutdown after the script completes?
I'm on Ubuntu if it matters.
Just do these three commands in one script:
service mysql start
mysql -umyuser -pmypass < /path/to/your/startup.sql
service mysql stop
You may consider using skip-networking in your /etc/mysql/my.cnf file so that the database is not accidentally accessed by anyone else for the short perios when it's up and running. In which case add the --socket argument to your mysql client command.
I've updated the my.cnf file of my database with the following line: max_connections=200. I stopped and started the mysql service after that so that the changes would take effect.
But for some reason this change doesn't affect the database because if I run:
mysql> select ##max_connections
it shows that the max number of connections is 100.
Obviously there is some place else that manages this value. Where can I find it or what did I do wrong?
Thank you for your reply.
Make sure the max_connections in under the [mysqld] section:
Ex:
[mysqld]
socket=/path/to/mysql.sock
datadir=/var/lib/mysql
max_connections=200
[client]
#mysql-client settings here..
Try running mysqld --verbose --help to see which configuration file is actually read by mysqld and which parameters and values are used.
The output will look like this:
mysqld Ver 5.0.51a-24-log for debian-linux-gnu on x86_64 ((Debian))
Copyright (C) 2000 MySQL AB, by Monty and others
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Default options are read from the following files in the given order:
/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf
The following groups are read: mysql_cluster mysqld server mysqld-5.0
Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
--------------------------------- -----------------------------
...
To see what values a running MySQL server is using, type
'mysqladmin variables' instead of 'mysqld --verbose --help'.
Changes to mysqld are not necessarily reflected in the mysql client! I changed a global variable assignment in my.cnf, restarted the service, and queried it in the mysql client. It returned the old value. When queried from a script, however, the value was in fact changed!
It may have to do with 'how' the mysql server is being shutdown and restarted. On my system if I use the mysqld daemon service to shutdown mysql (e.g. service mysqld stop), I get a shutdown notice, but a ps shows mysql is still running. Using a similar 'service mysqld restart', some of the changes to the my.cnf file get accepted, but many don't.
The other method of shutting down mysql is to use mysqladmin -u user -pPass shutdown. I noticed when I used this method, mysql was shutdown completely (no left overs in ps), and when I restarted the mysql server, all the changes to the my.cnf file were accepted.
If mysql starts as a Window service, check the 'Path to executable' setting on the windows service. (Services -> MYSQL56 -> Properties).
If the --defaults-file option is passed in, it could point to a completely different .ini file in a location that is NOT showing with 'mysqld --verbose --help'.
If you remove the --defaults-file option from the service startup parameters, it will go through the list of ini files as listed with mysqld --verbose --help.
Putting my.cnf in /etc/my.cnf and restarting mysql has resolved the issue for me. I'm using mac os. Mysql version is 5.6.41
I'm trying to determine which my.cnf mysql is using. Is there a command or something for mysql or mysqladmin that shows which one is being loaded?
On my linux servers in the startup script (/etc/init.d/mysql) it defines
CONF=/etc/mysql/my.cnf
that it uses to start MySQL daemon
EDIT:
also running
mysqld --verbose --help
shows the following info:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
So if run as a daemon through init script it will look into /etc/mysql/my.cnf and if started from the command line it will look there only on the second attempt.
the command
SHOW VARIABLES
Will give you a list of variables the current instance of mysql uses.
In the version of mysql I am currently running there is no trace of a my.cnf variable though, so thats not much help
You can always set one of the variables to a different value in each of your my.cnf's, restart the server and use the above command to figure out which configuration it loaded.