+---------------------+------------+ | now() | curdate() | +---------------------+------------+ | 2018-06-26 12:38:22 | 2018-06-26 | +---------------------+------------+
+-------------------------+ | now() - interval 40 day | +-------------------------+ | 2018-05-17 12:39:03 | +-------------------------+
+-----------------------------+ | curdate() - interval 40 day | +-----------------------------+ | 2018-05-17 | +-----------------------------+
+--------------------------------------+ | date_sub(curdate(), interval 40 day) | +--------------------------------------+ | 2018-05-17 | +--------------------------------------+
2019-11-05T14:19:05.852712Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid endedRun :
+------+-----------+-------------------------------------------+-------------------------------------------+ | user | host | authentication_string | PASSWORD("newRootPassword") | +------+-----------+-------------------------------------------+-------------------------------------------+ | root | localhost | *C45EE169D5D766B74FE801AB43D8DCB09A61837A | *C45EE169D5D766B74FE801AB43D8DCB09A61837A | | root | % | *C45EE169D5D766B74FE801AB43D8DCB09A61837A | *C45EE169D5D766B74FE801AB43D8DCB09A61837A | +------+-----------+-------------------------------------------+-------------------------------------------+ 2 rows in set, 1 warning (0.00 sec)
mysql> show master status; Empty set (0.00 sec)
mysql> show binary logs; ERROR 1381 (HY000): You are not using binary loggingThis is getting weird, because I'm in the context of a master-slave replication, and binary logging IS enabled. Something unexpected may have happened...
systemctl gave some good hints :
Mar 21 01:15:02 mysql mysqld[29666]: FAILFAILFAILFAILFAILFAILFAILFAILFAILFAIL180321 1:15:02 [ERROR] The table 'tableName' is full Mar 21 01:21:00 mysql mysqld[29666]: 180321 1:21:00 [Warning] mysqld: Disk is full writing '/var/lib/mysql/data/binlogs/mysql-bin.000010' (Errcode: 28 "No space left on device"). Waiting for someone to free space... (Expect up to 60 secs delay for server to continue after freeing disk space) Mar 21 01:21:00 mysql mysqld[29666]: 180321 1:21:00 [Warning] mysqld: Retry in 60 secs. Message reprinted in 600 secs Mar 21 01:22:00 mysql mysqld[29666]: 180321 1:22:00 [Warning] mysqld: Disk is full writing '/var/lib/mysql/data/binlogs/mysql-bin.000010' (Errcode: 28 "No space left on device"). Waiting for someone to free space... (Expect up to 60 secs delay for server to continue after freeing disk space) Mar 21 01:22:00 mysql mysqld[29666]: 180321 1:22:00 [Warning] mysqld: Retry in 60 secs. Message reprinted in 600 secs Mar 21 01:32:00 mysql mysqld[29666]: 180321 1:32:00 [Warning] mysqld: Retry in 60 secs. Message reprinted in 600 secs Mar 21 01:34:00 mysql mysqld[29666]: 180321 1:34:00 [ERROR] Could not use /var/lib/mysql/data/binlogs/mysql-bin for logging (error 0). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it. Mar 21 01:34:00 mysql mysqld[29666]: 180321 1:34:00 [ERROR] Could not open /var/lib/mysql/data/binlogs/mysql-bin.000011 for logging (error 0). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it. Trying to open the next binlog Mar 21 01:34:00 mysql mysqld[29666]: 180321 1:34:00 [ERROR] mysqld: Error writing file '(null)' (errno: 9 "Bad file descriptor")
-- Unit mariadb.service has begun starting up.
Dec 12 15:48:34 myServer systemd[3474]: mariadb.service: Failed at step NAMESPACE spawning /usr/bin/install: Too many levels of symbolic links
-- Subject: Process /usr/bin/install could not be executed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The process /usr/bin/install could not be executed and failed.
Some hints found on serverfault.com did not help fixing it.
The Too many levels of symbolic links message disappeared after I removed a hack in my setup where /root actually symlinked to /home/root (allowing to have all my scripts on the /home partitions and survive re-installs )phpinfo();
) :
Configuration File (php.ini) Path /etc/php/7.0/cgi Loaded Configuration File /etc/php/7.0/cgi/php.ini Scan this dir for additional .ini files /etc/php/7.0/cgi/conf.d
select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
When connected to MySQL as root, you're known as root@localhost.
File: mysql-bin.000363 Position: 55657
Master_Log_File: mysql-bin.000363 Read_Master_Log_Pos: 55657
set | update | |
---|---|---|
from the system shell | mysqladmin -u root password newMysqlRootPassword
Works only when the root account has no password at all |
to do |
from the MySQL shell | to do | update mysql.user set password=password('newMysqlRootPassword') where user='root';
Don't forget to flush privileges; to reload the grant tables in memory |
CREATE USER 'stuart'@'localhost' IDENTIFIED BY 'password'; GRANT ALL ON customer.* TO 'stuart'@'localhost' WITH MAX_USER_CONNECTIONS 2;
GRANT USAGE ON *.* TO 'stuart'@'localhost' WITH MAX_USER_CONNECTIONS 100;
GRANT USAGE ON *.* TO 'stuart'@'localhost' WITH MAX_USER_CONNECTIONS 0;
The per-account MAX_USER_CONNECTIONS overrides the global max_user_connections :
+---------------------------+ | FROM_UNIXTIME(1262428560) | +---------------------------+ | 2010-01-02 11:36:00 | +---------------------------+
+---------------------------------------+ | UNIX_TIMESTAMP('2014-01-03 17:21:42') | +---------------------------------------+ | 1388766102 | +---------------------------------------+
srcDbServer='prodServer'; srcDbUser='root'; srcDbPass='password'; srcDbName='prodDbName'; dstDbServer='devServer'; dstDbUser='root'; dstDbPass='password'; dstDbName='devDbName'; regExpNeedle='prod\.example\.com'; regExpReplacement='dev\.example\.com'; mysqldump -h $srcDbServer -u $srcDbUser -p$srcDbPass $srcDbName | sed "s/$regExpNeedle/$regExpReplacement/g" | mysql -h $dstDbServer -u $dstDbUser -p$dstDbPass $dstDbName
+------------+ | fieldName | +------------+ | 1234 | +------------+into 1234. As is, this command only supports numeric values.
TAB
into ;
$csvFile
:
select password("you can use any string"); select SHA1(UNHEX(SHA1("you can use any string")));
CREATE TABLE tableName(line blob); LOAD DATA INFILE '/file/to/read' INTO TABLE tableName; SELECT * FROM tableName;
file='/file/to/read'; dbUser='bob'; dbPass='password'; dbName='testDb'; tableName='testTable'; mysql -u $dbUser -p$dbPass -e "create database $dbName; use $dbName; create table $tableName(line blob); load data infile '$file' into table $tableName; select * from $tableName; drop database $dbName;"
SELECT "data to write comes here..." INTO OUTFILE "/path/to/file";
This requires the directory /path/to/ to be writable by everybody
If the views are exported from a server to be imported on another, the views definers may not match, resulting in a MySQL 1449 error. To fix this, edit views.sql and replace all occurrences of :
DEFINER=`wrongUser`@`wrongHost`with
DEFINER=`rightUser`@`rightHost`
optimize table myTable;
DBs don't grow in size unnecessarily, but for performance issues space is not freed either. If you delete records, the freed space is not given back to the operating system. Instead, it's kept as an empty space for the DB to re-use afterwards. This is because :dbHost='mysqlServer'; myUser='root'; myPassword='password'; mysql -h $dbHost -u $myUser -p"$myPassword" -e "SELECT user, count(1) as nbProcesses FROM information_schema.processlist GROUP BY user ORDER BY nbProcesses DESC;"
watch -n 2 -d "dbHost='mysqlServer'; myUser='root'; myPassword='password'; mysql -h $dbHost -u $myUser -p\"$myPassword\" -e \"SELECT user, count(1) AS nbProcesses FROM information_schema.processlist GROUP BY user ORDER BY nbProcesses DESC;\""
dbHost='mysqlServer'; evilDbUser='evilUser'; myUser='root'; myPassword='password'; for PID in $(mysql -h $dbHost -u $myUser -p"$myPassword" -e "SELECT id FROM information_schema.processlist WHERE user=\"$evilDbUser\";" | grep -v 'id'); do echo 'KILL : '$PID; mysql -h $dbHost -u $myUser -p"$myPassword" -e "kill $PID;"; done
myUser='root'; myPassword='password'; myDb='databaseName'; for PID in $(mysql -u $myUser -p"$myPassword" -e 'show processlist;' | grep $myDb | cut -f1); do echo 'KILL !'; mysql -u $myUser -p$myPassword -e "kill $PID;"; done
mysqlHost="mysqlServer"; myUser='root'; myPassword='password'; myDb='databaseName'; for PID in $(mysql -h $mysqlHost -u $myUser -p"$myPassword" -e 'show processlist;' | grep $myDb | cut -f1); do echo 'KILL !'; mysql -h $mysqlHost -u $myUser -p$myPassword -e "kill $PID;"; done
SELECT user, COUNT(user) AS nbProcess FROM information_schema.PROCESSLIST GROUP BY user ORDER BY COUNT(user) DESC
SELECT U.user, COUNT(PL.user) AS nbProcess FROM mysql.user U LEFT JOIN information_schema.PROCESSLIST PL ON PL.user=U.user GROUP BY U.user ORDER BY COUNT(PL.user) DESC
SELECT table_schema AS dbName, ROUND( SUM( data_length + index_length ) / 1024 / 1024, 3 ) AS dbSizeMb FROM information_schema.TABLES WHERE table_schema="myDatabase" GROUP BY table_schema;
MariaDB :
SUM
and (
SELECT table_name, table_rows, ROUND(( data_length + index_length ) / 1024 / 1024, 0) AS table_size_MB FROM information_schema.tables WHERE table_schema="dbName" ORDER BY table_size_MB DESC, table_rows DESC;
If you're just looking for the biggest table(s), try this : dbName='myDb; ls -Shl "/var/lib/mysql/$dbName" | head -20
SELECT table_name, table_rows, ROUND(( data_length + index_length ) / 1024 / 1024, 2) AS table_size_MB FROM information_schema.TABLES WHERE table_schema = "piwik" AND table_name = "piwik_log_link_visit_action";
create database databaseName;
The engine, charset and collation are table parameters, so no need to worry here (?)
revoke all, grant option from 'bob'@'host'; revoke all on *.* from 'bob'@'host'; flush privileges; drop user 'bob'@'host';
mysqlUserName='Bob'; mysqlUserHost='192.168.0.42'; mysql -u root -ppassword -e "revoke all, grant option from '$mysqlUserName'@'$mysqlUserHost'; revoke all on *.* from '$mysqlUserName'@'$mysqlUserHost'; flush privileges; drop user '$mysqlUserName'@'$mysqlUserHost';"
SELECT U.user, U.host, IF (password('clearPassword')=U.password,'Yes','No') AS 'passwords match ?' FROM mysql.user U WHERE U.user='bob';
+----------------+----------------+ | user() | current_user() | +----------------+----------------+ | root@localhost | root@localhost | +----------------+----------------+
dbNameCurrent='oldDbName'; dbNameNew='newDbName'; dbUser='bob'; dbPassword='password'; stringOk='[OK]'; stringKo='[KO]'; echo -n "Creating new empty DB \"$dbNameNew\" ... "; mysql -u $dbUser -p$dbPassword -e "create database $dbNameNew" && { echo $stringOk; for t in $(mysql -u $dbUser -p$dbPassword -e "show tables from $dbNameCurrent;" | grep -v "Tables_in_$dbNameCurrent"); do echo -n "Renaming table \"${dbNameCurrent}.$t\" into \"${dbNameNew}.$t\" ... "; mysql -u $dbUser -p$dbPassword -e "RENAME TABLE ${dbNameCurrent}.$t TO ${dbNameNew}.$t" && echo $stringOk || echo $stringKo; done; echo -n "Checking whether old DB \"$dbNameCurrent\" can be dropped ... "; [ $(mysql -u $dbUser -p$dbPassword -e "SELECT count(1) as '' FROM information_schema.TABLES WHERE table_schema= '$dbNameCurrent'") -eq 0 ] && { echo $stringOk; echo -n "Removing old DB \"$dbNameCurrent\" ... "; mysql -u $dbUser -p$dbPassword -e "DROP DATABASE $dbNameCurrent" && echo $stringOk || echo $stringKo; } || { echo "$stringKo : Can't drop $dbNameCurrent, not empty database."; } } || echo $stringKo
SELECT DISTINCT `table_schema` FROM information_schema.tables WHERE engine = "InnoDB"; SELECT `table_schema`,`table_name` FROM information_schema.tables WHERE engine = "InnoDB";
innodb_file_per_table = true innodb_data_file_path = ibdata1:10M:autoextend
Information below may be outdated / obsolete. Use at your own risk !
[mysqld]
section and add :
log-bin=/data/mysql/binlog_masterServer server-id=1This way, the binary log is enabled at each MySQL restart, independently of other options.
binlog-do-db=test_db
binlog-do-db and binlog-ignore-db respectively white-list or black-list the database to replicate. None is better than the other, it's just a matter of building the shortest list.
server-id=2 master-host=172.20.20.45 master-user=slave master-password=passwordForSlaveUserOnMasterDetails :
If Position is > 0, this means the binary log is active.
You should see both Slave_IO_Running and Slave_SQL_Running displaying YES.
and have a look at the Last_Error returned field. Looks like when an error is found by a slave in any binlog (i.e. a missing table), the processing of the binlog stops.
This error occurred while performing master-slave replication between a MySQL 4.1.20 master and a MySQL 5.0.45 slave, where a table field was defined as datetime and trying to be inserted a NULL value. Apparently, this is no big trouble for MySQL 4.x as this error never came up before, while replicating the same table.
To fix it :
See also :
mysql -u bob -ppassword --opt --databases dbName > dbName.sql
Option | Usage |
---|---|
-B --databases |
specify that following arguments are database names, not table names. Additionally, this adds a USE dbName; statement to the dump.
Using this directive with mysqldump will prevent importing the dump into a database having a different name.
|
-C --compress | Compress all information sent between the client and the server if both support compression |
-d --no-data | Dump only the create table statements and not the table contents. |
-l --lock-tables | lock all tables of a database before exporting it. Thus, the only locked tables are those of the database currently being exported |
--add-drop-table | add a "DROP" statement before any "CREATE TABLE" |
--add-locks | to let "INSERT" queries run faster, lock the table before inserting data, and unlock it once done |
--extended-insert | use the multi-line "INSERT" method (?) |
--opt | similar to --add-drop-table --add-locks --create-options --disable-keys --extended-insert --lock-tables --quick --set-charset. This is enabled by default. |
--quick | push the result directly to the output device without buffering |
--single-transaction | The --single-transaction option and the --lock-tables option are mutually exclusive because LOCK TABLES causes any pending transactions to be committed implicitly. To dump large tables, combine the --single-transaction option with the --quick. |
The idea is to make a "basic" database dump with mysqldump on a remote host, but instead of storing it into a file, we pipe it into a "mysql import" command :
truncate tableName
delete from tableName where [SQL condition]