KfWiki : MySql

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Revision [1966]

Most recent edit made on 2008-09-24 01:46:16 by WikiAdmin

Additions:

slow queries

%%(text; my.cnf)
log-slow-queries=/var/log/mysql-slow.log




Revision [1730]

Edited on 2008-05-26 22:45:55 by WikiAdmin

Additions:





Revision [1640]

Edited on 2008-04-14 07:23:38 by WikiAdmin

Additions:
MySQL multi master hack




Revision [1593]

Edited on 2008-04-01 20:55:36 by WikiAdmin

Additions:
$link = mysql_connect('localhost:/tmp/mysql.sock', 'mysql_user', 'mysql_password');


Deletions:
localhost:/tmp/mysql.sock




Revision [1592]

Edited on 2008-04-01 20:55:10 by WikiAdmin

Additions:

MySQL

php use socket instead of tcp

Put this in host parameter
localhost:/tmp/mysql.sock




Revision [1567]

Edited on 2008-03-27 01:34:58 by WikiAdmin

Additions:

DML
DDL
--key_buffer_size=128M --sort_buffer_size=128M \
--read_buffer_size=1M --write_buffer_size=1M \
/path/to/datadir/*/*.MYI


Deletions:

--key_buffer_size=128M --sort_buffer_size=128M \
--read_buffer_size=1M --write_buffer_size=1M \
/path/to/datadir/*/*.MYI




Revision [1513]

Edited on 2008-03-18 23:26:29 by WikiAdmin

Additions:
Encrypt MySQL connection with SSL




Revision [1392]

Edited on 2008-02-11 19:34:44 by WikiAdmin

Additions:
Show databases on remote host
Show processes on mysql
Show query statistics
Display table statistics
Export to CSV
Explain mysql error code


Deletions:
# Show databases on remote host
# Show processes on mysql
# Show query statistics
# Display table statistics
# Export to CSV
# Explain mysql error code




Revision [1391]

Edited on 2008-02-11 19:33:13 by WikiAdmin

Additions:
Inline sql
mysql -uroot -pxxx -se "show master status\G"




Revision [1266]

Edited on 2008-01-08 01:53:28 by WikiAdmin

Additions:
Or better yet, run mysql_check while your database is running
# mysql_check --all-databases
# mysql_check --databases db1 db2




Revision [1261]

Edited on 2008-01-07 01:36:27 by WikiAdmin

Additions:
If you need to run diagnosis when the database is running, use check table instead:




Revision [1260]

Edited on 2008-01-07 01:35:33 by WikiAdmin

Additions:
myisamchk can be ran only when the database are shutdown. Otherwise, there will be an error similar to this one:
Checking MyISAM file: ./roundcubemail/identities.MYI
Data records: 1 Deleted blocks: 0
myisamchk: warning: 1 client is using or hasn't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check record links
MyISAM-table './roundcubemail/identities.MYI' is usable but should be fixed




Revision [1259]

Edited on 2008-01-07 01:34:12 by WikiAdmin

Additions:

Checking mysql tables

sh> myisamchk ./*/*.MYI
mysql> check table db.table_name;




Revision [1244]

Edited on 2008-01-01 20:52:31 by WikiAdmin

Additions:





Revision [1082]

Edited on 2007-10-23 21:03:12 by WikiAdmin

Additions:
# Explain mysql error code
perror nnn
$ perror 139
MySQL error code 139: Too big row




Revision [963]

Edited on 2007-09-13 00:18:40 by WikiAdmin

Additions:
# Export to CSV
select * from TABLE into outfile '/tmp/domains.csv' fields terminated by ',' optionally enclosed by '"';




Revision [936]

Edited on 2007-09-06 23:03:58 by WikiAdmin

Additions:





Revision [916]

Edited on 2007-09-03 07:47:13 by WikiAdmin

Additions:





Revision [913]

Edited on 2007-08-30 20:29:05 by WikiAdmin

Additions:





Revision [810]

The oldest known version of this page was edited on 2007-07-25 21:58:01 by WikiAdmin
HomePage » Database » MySQL


Sub Topics
Installation
Indexes
Tuning
Backup/Import/Export
SSL
Mysql3 to Mysql4 upgrade
Resetting root password
Replication

Good articles
MySQL slave lag behind

MySQL useful commands

# Show databases on remote host
mysqlshow -h 1.2.3.4 -u root -p

# Show processes on mysql
mysqladmin -u root proc
or
mysql> SHOW PROCESSLIST;
mysql> SHOW PROCESSLIST \G
mysql> kill 123

# Show query statistics
mysql> explain select ~ from table \G

# Display running variables
mysql> SHOW VARIABLES;
mysql> SHOW STATUS;

# Display table statistics
mysql> show table status;
mysql> show table status like 'wikka%';



Upgrading mysql

Run mysql_upgrade to check your tables
To move a database to another host is
shell> mysqladmin -h 'other_hostname' create db_name
shell> mysqldump --opt db_name | mysql -h 'other_hostname' db_name


To copy a database from a remote host
shell> mysqladmin create db_name
shell> mysqldump -h 'other_hostname' --opt --compress db_name | mysql db_name


To copy a database in two phases, dump the database and import it to the new host

# On source db
shell> mysqldump --quick db_name | gzip > db_name.gz
# On target db
shell> mysqladmin create db_name
shell> gunzip < db_name.gz | mysql db_name


Data checking

myisamchk table_file
# Check all tables
myisamchk --silent --fast /path/to/datadir/~/~.MYI
# Recover datafile
myisamchk -i -r [-f] [-o] /path/to/datadir/*.MYI
# -o: safe recover, much slower but is able to fix more
# -f: force
OR
myisamchk --silent --force --fast --update-state \
	      --key_buffer_size=128M --sort_buffer_size=128M \
	      --read_buffer_size=1M --write_buffer_size=1M \
	      /path/to/datadir/*/*.MYI


To perform checking while database is in use, use check table command
CHECK TABLE test_table FAST QUICK;
# fast option: Check only tables that have not been closed properly.
# quick: Do not scan the rows to check for incorrect links.


max_connection_errors

When mysql detects more than 10 connection failures, such as bad password or bad tcp connection from the same host, the host will be blocked. It will throw an error suggesting a "mysqladmin flush-hosts". This could be an indication of a brute force password attack. Such limit can be overridden by supplying the following options to start up
--max_connection_errors=30

But of course, you would most likely want to see if someone was trying to get to your database. To do so, enable connection logging by

--log-warnings


Mysql can also be started with the -l=[filename] option to log all general queries. This file will contain what mysql is doing. Log can be rotated by

mv host_name.log host_name-old.log
mysqladmin flush-logs
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.7969 seconds