<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://aznot.com/index.php?action=history&amp;feed=atom&amp;title=MySQL</id>
	<title>MySQL - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://aznot.com/index.php?action=history&amp;feed=atom&amp;title=MySQL"/>
	<link rel="alternate" type="text/html" href="https://aznot.com/index.php?title=MySQL&amp;action=history"/>
	<updated>2026-04-28T23:00:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://aznot.com/index.php?title=MySQL&amp;diff=4564&amp;oldid=prev</id>
		<title>Kenneth: /* MySQL CLI Commands */</title>
		<link rel="alternate" type="text/html" href="https://aznot.com/index.php?title=MySQL&amp;diff=4564&amp;oldid=prev"/>
		<updated>2018-01-04T05:21:47Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;MySQL CLI Commands&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== MySQL ==&lt;br /&gt;
:&amp;quot;MySQL, the most popular Open Source SQL database management system, is developed, distributed, and supported by MySQL AB. MySQL AB is a commercial company, founded by the MySQL developers. It is a second generation Open Source company that unites Open Source values and methodology with a successful business model.&amp;quot; [http://dev.mysql.com/doc/refman/5.0/en/what-is-mysql.html]&lt;br /&gt;
&lt;br /&gt;
== Subpage Table of Contents ==&lt;br /&gt;
&lt;br /&gt;
{{Special:PrefixIndex/{{PAGENAME}}/}}&lt;br /&gt;
&lt;br /&gt;
==Pronunciation==&lt;br /&gt;
:&amp;quot;The official way to pronounce “MySQL” is “My Ess Que Ell” (not “my sequel”), but we don&amp;#039;t mind if you pronounce it as “my sequel” or in some other localized way.&amp;quot; [http://dev.mysql.com/doc/refman/5.0/en/what-is-mysql.html]&lt;br /&gt;
&lt;br /&gt;
==SunSQL==&lt;br /&gt;
MySQL is now owned by Sun Microsystems.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;we&amp;#039;re (Sun Microsystems) acquiring MySQL AB&amp;quot; [http://blogs.sun.com./jonathan/date/20080116]&lt;br /&gt;
&lt;br /&gt;
==MySQL CLI Commands==&lt;br /&gt;
Connect to MySQL&lt;br /&gt;
 mysql -h &amp;lt;host&amp;gt; -u &amp;lt;user&amp;gt; -p&amp;lt;password&amp;gt; &amp;lt;database&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 $ mysql -u root -p&lt;br /&gt;
   mysql&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show all databases:&lt;br /&gt;
 SHOW DATABASES;&lt;br /&gt;
&lt;br /&gt;
Show database create info:&lt;br /&gt;
 SHOW CREATE DATABASE [database_name];&lt;br /&gt;
&lt;br /&gt;
Select database:&lt;br /&gt;
 USE &amp;lt;database&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Show all tables in current database:&lt;br /&gt;
 SHOW TABLES;&lt;br /&gt;
&lt;br /&gt;
Describe table layout (Show all columns in a table):&lt;br /&gt;
 SHOW COLUMNS FROM &amp;lt;table_name&amp;gt;;&lt;br /&gt;
 DESC &amp;lt;table_name&amp;gt;;    # DESCRIBE &amp;lt;table_name&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Exit MySQL CLI:&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
Show MySQL variables (ie. max_connections):&lt;br /&gt;
 SHOW VARIABLES;&lt;br /&gt;
 SHOW VARIABLES LIKE &amp;#039;max_connections&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Show a list of processes (rough estimation of the number of connections):&lt;br /&gt;
 SHOW PROCESSLIST;&lt;br /&gt;
&lt;br /&gt;
Grant privileges (it is important to do localhost also, or anonymous takes over):&lt;br /&gt;
 grant all (privileges) on &amp;lt;db|*&amp;gt;.&amp;lt;table_name|*&amp;gt; to &amp;quot;&amp;lt;user&amp;gt;&amp;quot;@&amp;quot;&amp;lt;host|%&amp;gt;&amp;quot; identified by &amp;quot;&amp;lt;password&amp;gt;&amp;quot; (with Grant option);&lt;br /&gt;
 &lt;br /&gt;
Have server to reload grant table:&lt;br /&gt;
 flush privileges;&lt;br /&gt;
 &lt;br /&gt;
Drop user&lt;br /&gt;
 drop user &amp;lt;username&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
Revoke privileges&lt;br /&gt;
 revoke all PRIVILEGES, GRANT OPTION FROM &amp;lt;user&amp;gt;,&amp;lt;user...&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
Set password&lt;br /&gt;
 set password for &amp;#039;&amp;lt;user&amp;gt;&amp;#039;@&amp;#039;&amp;lt;host&amp;gt;&amp;#039; = password(&amp;#039;&amp;lt;newpassword&amp;gt;&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
=== Create Table ===&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),&lt;br /&gt;
    -&amp;gt; species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE animals (&lt;br /&gt;
     id MEDIUMINT NOT NULL AUTO_INCREMENT,&lt;br /&gt;
     name CHAR(30) NOT NULL,&lt;br /&gt;
     PRIMARY KEY (id)&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Data types - https://dev.mysql.com/doc/refman/5.5/en/data-types.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Insert Into Table ===&lt;br /&gt;
&lt;br /&gt;
==Install MySQL==&lt;br /&gt;
 yum install mysql mysql-server&lt;br /&gt;
&lt;br /&gt;
===Installation Message===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
To start mysqld at boot time you have to copy&lt;br /&gt;
support-files/mysql.server to the right place for your system&lt;br /&gt;
&lt;br /&gt;
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !&lt;br /&gt;
To do so, start the server, then issue the following commands:&lt;br /&gt;
/usr/bin/mysqladmin -u root password &amp;#039;new-password&amp;#039;&lt;br /&gt;
/usr/bin/mysqladmin -u root -h otrs.lindonlabs.com password &amp;#039;new-password&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Alternatively you can run:&lt;br /&gt;
/usr/bin/mysql_secure_installation&lt;br /&gt;
&lt;br /&gt;
which will also give you the option of removing the test&lt;br /&gt;
databases and anonymous user created by default.  This is&lt;br /&gt;
strongly recommended for production servers.&lt;br /&gt;
&lt;br /&gt;
See the manual for more instructions.&lt;br /&gt;
&lt;br /&gt;
You can start the MySQL daemon with:&lt;br /&gt;
cd /usr ; /usr/bin/mysqld_safe &amp;amp;&lt;br /&gt;
&lt;br /&gt;
You can test the MySQL daemon with mysql-test-run.pl&lt;br /&gt;
cd mysql-test ; perl mysql-test-run.pl&lt;br /&gt;
&lt;br /&gt;
Please report any problems with the /usr/bin/mysqlbug script!&lt;br /&gt;
&lt;br /&gt;
The latest information about MySQL is available on the web at&lt;br /&gt;
http://www.mysql.com&lt;br /&gt;
Support MySQL by buying support/licenses at http://shop.mysql.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Security ===&lt;br /&gt;
&lt;br /&gt;
 mysql -u root&lt;br /&gt;
 use mysql;&lt;br /&gt;
 truncate user;&lt;br /&gt;
 truncate db;&lt;br /&gt;
 grant all on *.* to root@localhost with grant option;&lt;br /&gt;
 flush privileges;&lt;br /&gt;
&lt;br /&gt;
== Config Check ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;lint&amp;#039; for config check for mysql&lt;br /&gt;
&lt;br /&gt;
 [root@db opt]# /usr/libexec/mysqld --help&lt;br /&gt;
 110729 23:08:58 [Warning] option &amp;#039;max_join_size&amp;#039;: unsigned value 18446744073709551615 adjusted to 4294967295&lt;br /&gt;
 110729 23:08:58 [Warning] option &amp;#039;max_join_size&amp;#039;: unsigned value 18446744073709551615 adjusted to 4294967295&lt;br /&gt;
 110729 23:08:58 [ERROR] /usr/libexec/mysqld: unknown variable &amp;#039;storage_engine=InnoDb&amp;#039;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* How to check MySQL Config files - MySQL Performance Blog - http://www.mysqlperformanceblog.com/2008/02/12/how-to-check-mysql-config-files/&lt;br /&gt;
&lt;br /&gt;
==Change Password==&lt;br /&gt;
&lt;br /&gt;
===Set Root Password===&lt;br /&gt;
 # Set root password the first time&lt;br /&gt;
 /usr/bin/mysqladmin -u root password &amp;#039;new-password&amp;#039;&lt;br /&gt;
 /usr/bin/mysqladmin -u root -h dev.y-t-c.com password &amp;#039;new-password&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 # Change root password&lt;br /&gt;
 mysqladmin -u root -p &amp;lt;oldpassword&amp;gt; &amp;lt;newpass&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reset Forgot Root Password ===&lt;br /&gt;
&lt;br /&gt;
 # mysqld_safe --skip-grant-tables&lt;br /&gt;
 # mysql&lt;br /&gt;
 MYSQL&amp;gt; use mysql;&lt;br /&gt;
 MYSQL&amp;gt; flush privileges;&lt;br /&gt;
&lt;br /&gt;
 MYSQL&amp;gt; UPDATE mysql.user SET Password=PASSWORD(&amp;#039;MyNewPass&amp;#039;) WHERE User=&amp;#039;root&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
 MYSQL&amp;gt; grant all on *.* to &amp;#039;root&amp;#039;@&amp;#039;%&amp;#039; identified by &amp;#039;test12&amp;#039; with grant option&lt;br /&gt;
&lt;br /&gt;
 MYSQL&amp;gt; flush privileges;&lt;br /&gt;
 MYSQL&amp;gt; exit;&lt;br /&gt;
&lt;br /&gt;
===Set User Password===&lt;br /&gt;
[http://dev.mysql.com/doc/refman/5.0/en/set-password.html SET PASSWORD Syntax]&lt;br /&gt;
&lt;br /&gt;
 # Change user password&lt;br /&gt;
 mysqladmin -u &amp;lt;user&amp;gt; -p &amp;lt;oldpassword&amp;gt; &amp;lt;newpass&amp;gt;&lt;br /&gt;
 mysql&amp;gt; set password = password(&amp;quot;yournewpassword&amp;quot;); &lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; SET PASSWORD FOR &amp;#039;bob&amp;#039;@&amp;#039;%.loc.gov&amp;#039; = PASSWORD(&amp;#039;newpass&amp;#039;);&lt;br /&gt;
 # is equivalent to:&lt;br /&gt;
 mysql&amp;gt; UPDATE mysql.user SET Password=PASSWORD(&amp;#039;newpass&amp;#039;)&lt;br /&gt;
          WHERE User=&amp;#039;bob&amp;#039; AND Host=&amp;#039;%.loc.gov&amp;#039;;&lt;br /&gt;
 mysql&amp;gt; FLUSH PRIVILEGES;&lt;br /&gt;
&lt;br /&gt;
==Privileges==&lt;br /&gt;
[http://dev.mysql.com/doc/refman/5.0/en/grant.html GRANT Syntax]&lt;br /&gt;
 GRANT &amp;lt;privileges&amp;gt; ON &amp;lt;table_or_db_name&amp;gt; TO &amp;#039;&amp;lt;user&amp;gt;&amp;#039;@&amp;#039;&amp;lt;host&amp;gt;&amp;#039; IDENTIFIED BY &amp;#039;&amp;lt;password&amp;gt;&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Create user:&lt;br /&gt;
 CREATE USER &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt; IDENTIFIED BY &amp;#039;&amp;lt;password&amp;gt;&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Global Level:&lt;br /&gt;
 GRANT ALL ON *.* TO &amp;#039;someuser&amp;#039;@&amp;#039;somehost&amp;#039;;&lt;br /&gt;
 GRANT SELECT, INSERT ON *.* TO &amp;#039;someuser&amp;#039;@&amp;#039;somehost&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Table Level:&lt;br /&gt;
 GRANT ALL ON mydb.mytbl TO &amp;#039;someuser&amp;#039;@&amp;#039;somehost&amp;#039;;&lt;br /&gt;
 GRANT SELECT, INSERT ON mydb.mytbl TO &amp;#039;someuser&amp;#039;@&amp;#039;somehost&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Column Level:&lt;br /&gt;
 GRANT SELECT (col1), INSERT (col1,col2) ON mydb.mytbl TO &amp;#039;someuser&amp;#039;@&amp;#039;somehost&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Revoke Permission:&lt;br /&gt;
 REVOKE SELECT ON *.* FROM &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt;;&lt;br /&gt;
 DROP USER &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
List MySQL privileges:&lt;br /&gt;
 SHOW PRIVILEGES;&lt;br /&gt;
&lt;br /&gt;
Show privileges for user:&lt;br /&gt;
 SHOW GRANTS FOR &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table class=&amp;quot;wikitable&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;caption&amp;gt;Privileges&amp;lt;/caption&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Privilege&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Meaning&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;ALL [PRIVILEGES]&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Sets all simple privileges except GRANT OPTION&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;ALTER&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of ALTER TABLE&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;ALTER ROUTINE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables stored routines to be altered or dropped&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;CREATE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of CREATE TABLE&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;CREATE ROUTINE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables creation of stored routines&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;CREATE TEMPORARY TABLES&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of CREATE TEMPORARY TABLE&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;CREATE USER&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES.&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;CREATE VIEW&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of CREATE VIEW&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;DELETE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of DELETE&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;DROP&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of DROP TABLE&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;EXECUTE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables the user to run stored routines&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;FILE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of SELECT ... INTO OUTFILE and LOAD DATA INFILE&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;INDEX&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of CREATE INDEX and DROP INDEX&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;INSERT&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of INSERT&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;LOCK TABLES&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of LOCK TABLES on tables for which you have the SELECT privilege&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;PROCESS&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables the user to see all processes with SHOW PROCESSLIST&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;REFERENCES&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Not implemented&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;RELOAD&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of FLUSH&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;REPLICATION CLIENT&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables the user to ask where slave or master servers are&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;REPLICATION SLAVE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Needed for replication slaves (to read binary log events from the master)&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;SELECT&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of SELECT&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;SHOW DATABASES&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;SHOW DATABASES shows all databases&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;SHOW VIEW&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of SHOW CREATE VIEW&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;SHUTDOWN&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of mysqladmin shutdown&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;SUPER&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of CHANGE MASTER, KILL, PURGE MASTER LOGS, and SET GLOBAL statements, the mysqladmin debug command; allows you to connect (once) even if max_connections is reached&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;UPDATE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables use of UPDATE&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;USAGE&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Synonym for “no privileges”&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;GRANT OPTION&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;Enables privileges to be granted&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.databasejournal.com/features/mysql/article.php/3311731 An introduction to MySQL permissions]:&lt;br /&gt;
&lt;br /&gt;
The table mysql.user has all db users.&lt;br /&gt;
 USE mysql;&lt;br /&gt;
 DESC user;&lt;br /&gt;
&lt;br /&gt;
Show host and user pairs:&lt;br /&gt;
 SELECT host, user FROM user;&lt;br /&gt;
 SELECT host, uuser, select_priv, insert_priv FROM user;&lt;br /&gt;
&lt;br /&gt;
If the user table allows access, but disallows permission for a particular operation, the next table to worry about is the db table.&lt;br /&gt;
 DESC db;&lt;br /&gt;
 SELECT host, db, user, select_priv, insert_priv FROM db;&lt;br /&gt;
&lt;br /&gt;
The order of precedence of the tables is as follows:&lt;br /&gt;
# user&lt;br /&gt;
# db/host&lt;br /&gt;
# tables_priv&lt;br /&gt;
# columns_priv&lt;br /&gt;
&lt;br /&gt;
==Clear All Users==&lt;br /&gt;
Tables of concern:&lt;br /&gt;
 mysql.db&lt;br /&gt;
 mysql.user&lt;br /&gt;
&lt;br /&gt;
Clear all:&lt;br /&gt;
 DELETE FROM mysql.db;&lt;br /&gt;
 DELETE FROM mysql.user;&lt;br /&gt;
&lt;br /&gt;
Set default root access:&lt;br /&gt;
 GRANT ALL ON *.* TO &amp;#039;root&amp;#039;@&amp;#039;%&amp;#039; IDENTIFIED BY &amp;#039;password&amp;#039; WITH GRANT OPTION;&lt;br /&gt;
 FLUSH PRIVILEGES;&lt;br /&gt;
&lt;br /&gt;
==Export to file==&lt;br /&gt;
&lt;br /&gt;
===Export via Select===&lt;br /&gt;
[http://dev.mysql.com/doc/refman/5.0/en/select.html Mysql: Select]:&lt;br /&gt;
:&amp;quot;The SELECT ... INTO OUTFILE &amp;#039;file_name&amp;#039; form of SELECT writes the selected rows to a file.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The file is written to the mysql data directory, so you have to have write access to this folder.&lt;br /&gt;
&lt;br /&gt;
===Export via CLI===&lt;br /&gt;
The better solution:&lt;br /&gt;
:&amp;quot;If you want to create the resulting file on some client host other than the server host, you cannot use SELECT ... INTO OUTFILE. In that case, you should instead use a command such as mysql -e &amp;quot;SELECT ...&amp;quot; &amp;gt;  file_name to generate the file on the client host.&amp;quot; [http://dev.mysql.com/doc/refman/5.0/en/select.html]&lt;br /&gt;
&lt;br /&gt;
Summary:&lt;br /&gt;
 mysql -u &amp;lt;user&amp;gt; -p&amp;lt;password&amp;gt; &amp;lt;db&amp;gt; &amp;lt;format&amp;gt; -e &amp;lt;QUERY&amp;gt;&lt;br /&gt;
 mysql -u root -pMyPassword cca -t -e &amp;quot;SELECT * FROM TABLE1;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Export in tab separated format (default format):&lt;br /&gt;
 -B  --batch&lt;br /&gt;
&lt;br /&gt;
Export in table format:&lt;br /&gt;
 -t  --table&lt;br /&gt;
&lt;br /&gt;
Export in HTML format:&lt;br /&gt;
 -H  --html&lt;br /&gt;
&lt;br /&gt;
Export in XML format:&lt;br /&gt;
 -X  --xml&lt;br /&gt;
&lt;br /&gt;
Example of multi-line&lt;br /&gt;
 mysql -u kenneth -p cca &amp;lt;&amp;lt;EOL | mail kenneth.burgener@contractpal.com -s &amp;quot;daily.report.$(date +%Y.%m.%d)&amp;quot;&lt;br /&gt;
 SELECT col1, col2&lt;br /&gt;
 FROM mytable&lt;br /&gt;
 EOL&lt;br /&gt;
&lt;br /&gt;
== Common Server Settings ==&lt;br /&gt;
&lt;br /&gt;
Default Red Hat MySQL settings:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
datadir=/var/lib/mysql&lt;br /&gt;
socket=/var/lib/mysql/mysql.sock&lt;br /&gt;
# Default to using old password format for compatibility with mysql 3.x&lt;br /&gt;
# clients (those using the mysqlclient10 compatibility package).&lt;br /&gt;
old_passwords=1&lt;br /&gt;
&lt;br /&gt;
[mysql.server]&lt;br /&gt;
user=mysql&lt;br /&gt;
basedir=/var/lib&lt;br /&gt;
&lt;br /&gt;
[mysqld_safe]&lt;br /&gt;
log-error=/var/log/mysqld.log&lt;br /&gt;
pid-file=/var/run/mysqld/mysqld.pid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Performance changes:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
...&lt;br /&gt;
max_connections = 500&lt;br /&gt;
max_allowed_packet = 100M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Query Cache ===&lt;br /&gt;
&lt;br /&gt;
Enable the query cache in MySQL to improve performance - http://www.cyberciti.biz/tips/enable-the-query-cache-in-mysql-to-improve-performance.html&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; SHOW VARIABLES LIKE &amp;#039;query_cache_size&amp;#039;;&lt;br /&gt;
 mysql&amp;gt; SHOW VARIABLES LIKE &amp;#039;query_cache_type&amp;#039;;&lt;br /&gt;
 mysql&amp;gt; SHOW VARIABLES LIKE &amp;#039;query_cache_limit&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
/etc/my.cnf:&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 # query_cache_size = 16777216&lt;br /&gt;
 # query_cache_limit = 1048576&lt;br /&gt;
 query_cache_size = 16M&lt;br /&gt;
 query_cache_type = 1&lt;br /&gt;
 query_cache_limit = 1M&lt;br /&gt;
&lt;br /&gt;
=== Packet Size ===&lt;br /&gt;
&lt;br /&gt;
/etc/my.cnf:&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 max_allowed_packet = 100M&lt;br /&gt;
&lt;br /&gt;
=== Connections ===&lt;br /&gt;
&lt;br /&gt;
/etc/my.cnf:&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 max_connections = 500&lt;br /&gt;
&lt;br /&gt;
== Server Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Storage Engine ===&lt;br /&gt;
&lt;br /&gt;
Set the default storage engine to InnoDB: [http://confluence.atlassian.com/display/DOC/Database+Setup+For+MySQL]&lt;br /&gt;
&lt;br /&gt;
/etc/my.cnf:&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 default-storage-engine = INNODB&lt;br /&gt;
&lt;br /&gt;
To verify storage engine:&lt;br /&gt;
 SHOW VARIABLES LIKE &amp;#039;storage_engine&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
=== default character set ===&lt;br /&gt;
&lt;br /&gt;
default character set to be UTF-8: [http://confluence.atlassian.com/display/DOC/Database+Setup+For+MySQL]&lt;br /&gt;
&lt;br /&gt;
/etc/my.cnf:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
...&lt;br /&gt;
default-collation = utf8_bin&lt;br /&gt;
character-set-server = utf8&lt;br /&gt;
collation-server = utf8_bin&lt;br /&gt;
default-character-set = utf8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the status command to verify database character encoding information:&lt;br /&gt;
 mysql&amp;gt; use fisheye;&lt;br /&gt;
 mysql&amp;gt; status;&lt;br /&gt;
&lt;br /&gt;
== Backup User Permissions ==&lt;br /&gt;
&lt;br /&gt;
 GRANT LOCK TABLES, SELECT ON mydatabase.* TO &amp;#039;backup&amp;#039;@&amp;#039;backuphost&amp;#039; IDENTIFIED BY &amp;#039;somecoolpassword&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
 GRANT LOCK TABLES, SELECT ON *.* TO &amp;#039;backup&amp;#039;@&amp;#039;%&amp;#039; IDENTIFIED BY &amp;#039;b@ckup&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
MySQL: Backup User Privileges&lt;br /&gt;
&lt;br /&gt;
Q: What privileges must I grant to a MySQL user to allow them to run mysqldump?&lt;br /&gt;
&lt;br /&gt;
A: LOCK TABLES, SELECT seems to do the trick.&lt;br /&gt;
&lt;br /&gt;
Example: GRANT LOCK TABLES, SELECT ON mydatabase.* TO &amp;#039;backup&amp;#039;@&amp;#039;backuphost&amp;#039; IDENTIFIED BY &amp;#039;somecoolpassword&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
Principle of least-privilege: don’t entrust your backup host with the power to hurt the database if you don’t have to. SELECT allows the user to read data, and LOCK TABLES allows the user to lock the tables while running a “snapshot” . . . and of course, narrow the privileges to a specific user-host-password tuple.&lt;br /&gt;
&lt;br /&gt;
Reference: dannyman.toldme.com : MySQL: Backup User Privileges - http://dannyman.toldme.com/2006/08/22/mysql-backup-grant-privileges/&lt;br /&gt;
&lt;br /&gt;
==Nightly Backup==&lt;br /&gt;
How to Schedule MySQL Backups in Windows [http://www.dailytechnology.net/how_to_back_up_mysql_with_windows.php]&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
Nightly MySQL Backup [http://www.andrejciho.com/linux/nightly-mysql-backup/]&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 &lt;br /&gt;
 #Define your variables here:&lt;br /&gt;
 BACKUP_DIR=&lt;br /&gt;
 BMYSQL_HOST=&lt;br /&gt;
 BMYSQL_DBNAME=&lt;br /&gt;
 BMYSQL_USER=&lt;br /&gt;
 BMYSQL_PWD=&lt;br /&gt;
 &lt;br /&gt;
 #  Make sure output directory exists.&lt;br /&gt;
 if [ ! -d $BACKUP_DIR ]; then&lt;br /&gt;
     mkdir -p $BACKUP_DIR&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 #  Rotate backups&lt;br /&gt;
 for j in  6 5 4 3 2 1 0; do&lt;br /&gt;
     for i in $BACKUP_DIR/$BMYSQL_DBNAME.gz.$j; do&lt;br /&gt;
         if [ -e $i ]; then&lt;br /&gt;
             mv $i ${i/.$j/}.$(( $j + 1 ));&lt;br /&gt;
         fi&lt;br /&gt;
     done&lt;br /&gt;
 done&lt;br /&gt;
 &lt;br /&gt;
 mysqldump --host=$BMYSQL_HOST --user=$BMYSQL_USER --pass=$BMYSQL_PWD $BMYSQL_DBNAME | gzip &amp;gt; $BACKUP_DIR/$BMYSQL_DBNAME.gz.0&lt;br /&gt;
&lt;br /&gt;
 crontab -e&lt;br /&gt;
&lt;br /&gt;
 # minute (0-59),&lt;br /&gt;
 # |      hour (0-23),&lt;br /&gt;
 # |      |       day of the month (1-31),&lt;br /&gt;
 # |      |       |       month of the year (1-12),&lt;br /&gt;
 # |      |       |       |       day of the week (0-6 with 0=Sunday).&lt;br /&gt;
 # |      |       |       |       |       commands&lt;br /&gt;
 15       1       *       *       *       /home/path/to/your/script&lt;br /&gt;
&lt;br /&gt;
 crontab -l&lt;br /&gt;
&lt;br /&gt;
==mysqldump==&lt;br /&gt;
[http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html mysqldump]&lt;br /&gt;
&lt;br /&gt;
To export:&lt;br /&gt;
 $ mysqldump [options] db_name [tables]&lt;br /&gt;
 $ mysqldump [options] --databases db_name1 [db_name2 db_name3...]&lt;br /&gt;
 $ mysqldump [options] --all-databases&lt;br /&gt;
&lt;br /&gt;
 mysqldump mysql -u USER -p DBNAME &amp;gt; dump.sql&lt;br /&gt;
&lt;br /&gt;
To import:&lt;br /&gt;
 mysql -u USER -p DBNAME &amp;lt; dump.sql&lt;br /&gt;
&lt;br /&gt;
Error on import:&lt;br /&gt;
 ERROR 1227 (42000) at line 2068: Access denied; you need the SUPER privilege for this operation&lt;br /&gt;
 /*!50001 CREATE ALGORITHM=UNDEFINED */&lt;br /&gt;
 /*!50013 DEFINER=`cca`@`localhost` SQL SECURITY DEFINER */&lt;br /&gt;
 &lt;br /&gt;
 /*!50001 CREATE ALGORITHM=UNDEFINED */&lt;br /&gt;
 /*!50013 DEFINER=`cca`@`qa.contractpal.com` SQL SECURITY DEFINER */&lt;br /&gt;
 &lt;br /&gt;
 http://dev.mysql.com/doc/refman/5.0/en/create-view.html&lt;br /&gt;
 &lt;br /&gt;
 &amp;quot;The default DEFINER value is the user who executes the CREATE VIEW statement. (This is the same as DEFINER = CURRENT_USER.) If a user value is given, it should be a MySQL account in &amp;#039;user_name&amp;#039;@&amp;#039;host_name&amp;#039;  format (the same format used in the GRANT  statement). The user_name and host_name values both are required.&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 Changing `localhost` or `qa.contractpal.com` to `%` appears to pass ok.&lt;br /&gt;
 Changing &amp;quot;`cca`@`localhost`&amp;quot; to just &amp;quot;CURRENT_USER&amp;quot; also works.&lt;br /&gt;
&lt;br /&gt;
 To fix:&lt;br /&gt;
 cat cca.sql | sed &amp;quot;s/DEFINER=\`cca\`@\`qa.contractpal.com\` SQL SECURITY DEFINER/DEFINER=CURRENT_USER SQL SECURITY DEFINER/g&amp;quot; &amp;gt; cca2.sql&lt;br /&gt;
 cat cca2.sql | sed &amp;quot;s/DEFINER=\`cca\`@\`localhost\` SQL SECURITY DEFINER/DEFINER=CURRENT_USER SQL SECURITY DEFINER/g&amp;quot; &amp;gt; cca3.sql&lt;br /&gt;
&lt;br /&gt;
==Binary Logs==&lt;br /&gt;
[http://dev.mysql.com/doc/refman/5.0/en/binary-log.html The Binary Log]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;quot;You can delete all binary log files with the RESET MASTER statement, or a subset of them with PURGE MASTER LOGS. See Section 12.5.5.5, “RESET Syntax”, and Section 12.6.1.1, “PURGE MASTER LOGS Syntax”.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*[http://dev.mysql.com/doc/refman/5.0/en/purge-master-logs.html PURGE MASTER LOGS Syntax]&lt;br /&gt;
*[http://dev.mysql.com/doc/refman/5.0/en/reset.html RESET Syntax]&lt;br /&gt;
&lt;br /&gt;
==Database Recovery using Binary Logs==&lt;br /&gt;
*[http://www.databasejournal.com/features/mysql/article.php/3326351 Restoring lost data from the Binary Update Log]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Error Log==&lt;br /&gt;
*[http://www.databasejournal.com/features/mysql/article.php/2112011 The Error Log]&lt;br /&gt;
*[http://www.science.uva.nl/ict/ossdocs/mysql/manual_Log_files.html The MySQL log files]&lt;br /&gt;
&lt;br /&gt;
==Reindexing Tables==&lt;br /&gt;
[http://www.experts-exchange.com/Databases/Mysql/Q_20854227.html MySQL reindex...]&lt;br /&gt;
&lt;br /&gt;
Help mysql make better choices about index usage:&lt;br /&gt;
 ANALYZE TABLE tablename;&lt;br /&gt;
&lt;br /&gt;
Use to defragment a table that had a large delete:&lt;br /&gt;
 OPTIMIZE TABLE tablename;&lt;br /&gt;
&lt;br /&gt;
Fixes corrupted tables/index:&lt;br /&gt;
 REPAIR TABLE tablename;&lt;br /&gt;
&lt;br /&gt;
If all goes well you may need the occasional ANALYZE TABLE, but you should not need to rebuild the index itself on any regular basis.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;quot;You don&amp;#039;t need to reindex MySQL&amp;#039;s tables;  ... this is one of the major benefits of the long lasting MySQL Vs Postgress discussion where Postgress requires you to run vacuum every certain amount of time.&lt;br /&gt;
&lt;br /&gt;
From the manual:&lt;br /&gt;
&lt;br /&gt;
OPTIMIZE TABLE should be used if you have deleted a large part of a table or if you have made many changes to a table with variable-length rows (tables that have VARCHAR, BLOB, or TEXT columns). Deleted records are maintained in a linked list and subsequent INSERT operations reuse old record positions. You can use OPTIMIZE TABLE to reclaim the unused space and to defragment the datafile.&lt;br /&gt;
&lt;br /&gt;
In most setups you don&amp;#039;t have to run OPTIMIZE TABLE at all. Even if you do a lot of updates to variable length rows it&amp;#039;s not likely that you need to do this more than once a month/week and only on certain tables.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Character Set ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Every database has a database character set and a database collation&amp;quot; [http://dev.mysql.com/doc/refman/5.0/en/charset-database.html]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;A character set is a set of symbols and encodings. A collation is a set of rules for comparing characters in a character set.&amp;quot; [http://dev.mysql.com/doc/refman/5.0/en/charset-general.html]&lt;br /&gt;
&lt;br /&gt;
List available character set options:&lt;br /&gt;
 SHOW CHARACTER SET;&lt;br /&gt;
 &lt;br /&gt;
 +----------+-----------------------------+---------------------+--------+&lt;br /&gt;
 | Charset  | Description                 | Default collation   | Maxlen |&lt;br /&gt;
 +----------+-----------------------------+---------------------+--------+&lt;br /&gt;
 | latin1   | cp1252 West European        | latin1_swedish_ci   |      1 |&lt;br /&gt;
 | utf8     | UTF-8 Unicode               | utf8_general_ci     |      3 |&lt;br /&gt;
 +----------+-----------------------------+---------------------+--------+&lt;br /&gt;
&lt;br /&gt;
latin1 is the mysql default character set.&lt;br /&gt;
&lt;br /&gt;
List available collation options:&lt;br /&gt;
 SHOW COLLATION;&lt;br /&gt;
 SHOW COLLATION LIKE &amp;#039;latin1%&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
 +----------------------+----------+-----+---------+----------+---------+&lt;br /&gt;
 | Collation            | Charset  | Id  | Default | Compiled | Sortlen |&lt;br /&gt;
 +----------------------+----------+-----+---------+----------+---------+&lt;br /&gt;
 | latin1_swedish_ci    | latin1   |   8 | Yes     | Yes      |       1 |&lt;br /&gt;
 | utf8_general_ci      | utf8     |  33 | Yes     | Yes      |       1 |&lt;br /&gt;
 +----------------------+----------+-----+---------+----------+---------+&lt;br /&gt;
&lt;br /&gt;
=== How do I set the database character set? ===&lt;br /&gt;
&lt;br /&gt;
Server settings (/etc/my.cnf):&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 character-set-server=latin1&lt;br /&gt;
 collation-server=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
Create database and specify UTF8 character set:&lt;br /&gt;
 CREATE [DEFAULT] DATABASE db_name CHARACTER SET utf8;&lt;br /&gt;
 CREATE [DEFAULT] DATABASE db_name CHARSET utf8;&lt;br /&gt;
 CREATE [DEFAULT] DATABASE db_name CHARSET utf8 COLLATE utf8_general_ci;&lt;br /&gt;
&lt;br /&gt;
The database character set and collation are used as default values if the table character set and collation are not specified in CREATE TABLE statements&lt;br /&gt;
&lt;br /&gt;
=== How do I determine the database character set? ===&lt;br /&gt;
&lt;br /&gt;
&amp;quot;All database options are stored in a text file named db.opt that can be found in the database directory.&amp;quot; [http://dev.mysql.com/doc/refman/5.0/en/charset-database.html]&lt;br /&gt;
&lt;br /&gt;
/var/lib/mysql/cca/db.opt:&lt;br /&gt;
 default-character-set=latin1&lt;br /&gt;
 default-collation=latin1_swedish_ci&lt;br /&gt;
&lt;br /&gt;
&amp;quot;The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables.  The server sets these variables whenever the default database changes. If there is no default database, the variables have the same value as the corresponding server-level system variables, character_set_server and collation_server.&amp;quot; [http://dev.mysql.com/doc/refman/5.0/en/charset-database.html]&lt;br /&gt;
&lt;br /&gt;
To discover the character set and collation of a database: [http://dev.mysql.com/doc/refman/5.0/en/charset-database.html]&lt;br /&gt;
 USE your_database_of_interest;&lt;br /&gt;
 show variables like &amp;quot;character_set_database&amp;quot;;&lt;br /&gt;
 show variables like &amp;quot;collation_database&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
To show the current character set use this query: [http://dev.mysql.com/doc/refman/5.0/en/charset-database.html]&lt;br /&gt;
 SHOW CREATE DATABASE `DB_NAME`&lt;br /&gt;
&lt;br /&gt;
To show a table&amp;#039;s character set:&lt;br /&gt;
 SHOW CREATE TABLE [table_name];&lt;br /&gt;
&lt;br /&gt;
To show databases character set:&lt;br /&gt;
 mysql&amp;gt; use mydb;&lt;br /&gt;
 mysql&amp;gt; status;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
*[http://dev.mysql.com/doc/refman/5.0/en/charset-database.html MySQL :: MySQL 5.0 Reference Manual :: 9.1.3.2 Database Character Set and Collation]&lt;br /&gt;
&lt;br /&gt;
=== Converting database character set ===&lt;br /&gt;
Alter database defaults [&lt;br /&gt;
 alter database cca charset = utf8 collate = utf8_general_ci;&lt;br /&gt;
&lt;br /&gt;
Convert character set:&lt;br /&gt;
 mysql -u root -pMyPassword cca -B -e &amp;quot;SHOW TABLES&amp;quot; | awk &amp;#039;{print &amp;quot;mysql -u root -pMyPassword cca -e \&amp;quot;alter table &amp;quot; $1 &amp;quot; convert to character set utf8 collate utf8_general_ci;\&amp;quot;&amp;quot;}&amp;#039; | sh&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
*[http://dev.mysql.com/doc/refman/5.0/en/alter-database.html MySQL :: MySQL 5.0 Reference Manual :: 12.1.1 ALTER DATABASE Syntax]&lt;br /&gt;
&lt;br /&gt;
Another Possible option:&lt;br /&gt;
*[http://codex.wordpress.org/Converting_Database_Character_Sets Converting Database Character Sets « WordPress Codex]&lt;br /&gt;
&lt;br /&gt;
====Dump Conversion====&lt;br /&gt;
Dump the database and remember to use --skip-set-charset, or use the sed command after you have created the dump&lt;br /&gt;
 mysqldump -u username -p --skip-set-charset database &amp;gt; dump.sql&lt;br /&gt;
&lt;br /&gt;
 sed -e &amp;#039;s/ DEFAULT CHARSET=UTF-8//&amp;#039; dump.sql &amp;gt; dump_fix.sql&lt;br /&gt;
&lt;br /&gt;
Convert to ISO-8859-1:&lt;br /&gt;
 iconv --from-code=UTF-8 --to-code=ISO-8859-1 dump.sql &amp;gt; new_dump.sql&lt;br /&gt;
&lt;br /&gt;
Dump database back to new server:&lt;br /&gt;
 mysql -u username -p database &amp;lt; new_dump.sql&lt;br /&gt;
&lt;br /&gt;
Source: [http://ez.no/developer/forum/install_configuration/database_charset_conversion_downgrade_sql_to_non_utf_8 Database charset conversion (downgrade sql to non utf-8) / Install &amp;amp; Configuration / Forum]&lt;br /&gt;
&lt;br /&gt;
== stored procedure ==&lt;br /&gt;
&lt;br /&gt;
== MySQL Slave with Multiple Master Replication ==&lt;br /&gt;
My researching indicates MySQL does not support a slave having multiple masters.  Replication was designed the other way around, for a master to have multiple slaves.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Replication enables data from one MySQL database server (called the master) to be replicated to one or more MySQL database servers (slaves).&amp;quot; [1]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;One of our requirements is to have multiple master databases merge into a single slave database. The built-in MySQL replication engine does not support this kind of setup.&amp;quot; [3]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Suggested Options:&lt;br /&gt;
&lt;br /&gt;
1. One option I think we can consider is installing two copies of MySQL on the same box, and having each installation act as a separate slave.&lt;br /&gt;
&lt;br /&gt;
2. A second option is we could chain the replication:&lt;br /&gt;
 SERVER A (transaction data master) -&amp;gt; SERVER B (transaction data slave, analytics data master) -&amp;gt; SERVER C (analytics data slave)&lt;br /&gt;
&lt;br /&gt;
3. A third option would be have both transaction and analytics hosted on the master server, and have one or two other database servers act as replication servers.&lt;br /&gt;
&lt;br /&gt;
4. Have a crazy stored procedure replication (not a very robust option) [3]&lt;br /&gt;
  Custom Replication - http://mysqlonrails.blogspot.com/2008/03/custom-replication.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
&lt;br /&gt;
[1] MySQL :: MySQL 5.0 Reference Manual :: 18 Replication http://dev.mysql.com/doc/refman/5.0/en/replication.html&lt;br /&gt;
&lt;br /&gt;
[2] 18.1.2. Replication Startup Options and Variables - http://dev.mysql.com/doc/refman/5.0/en/replication-options.html&lt;br /&gt;
&lt;br /&gt;
[3] Custom Replication - http://mysqlonrails.blogspot.com/2008/03/custom-replication.html&lt;br /&gt;
&lt;br /&gt;
[4] MySQL Replication - http://dev.mysql.com/doc/refman/5.0/en/replication.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== MySQL History ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/faq/howto-clear-mysql-command-history/ Clear mysql command line history stored in ~/.mysql_history file]&lt;br /&gt;
&lt;br /&gt;
 $ &amp;gt; ~/.mysql_history&lt;br /&gt;
&lt;br /&gt;
 $ rm $HOME/.mysql_history&lt;br /&gt;
 $ ln -s /dev/null $HOME/.mysql_history&lt;br /&gt;
&lt;br /&gt;
[http://www.cyberciti.biz/tips/howto-clear-screen-when-you-logout.html Shell tip: Clear the command history and screen when you log out]&lt;br /&gt;
&lt;br /&gt;
== ODBC ==&lt;br /&gt;
&lt;br /&gt;
MySQL :: MySQL 5.1 Reference Manual :: 21.1.3.1 Installing Connector/ODBC from a Binary Distribution on Windows - http://dev.mysql.com/doc/refman/5.1/en/connector-odbc-installation-binary-windows.html#connector-odbc-installation-binary-windows-installer&lt;br /&gt;
&lt;br /&gt;
MySQL :: MySQL on Windows - Why, Where and How - http://www.mysql.com/why-mysql/white-papers/mysql_on_windows_wwh.php&lt;br /&gt;
&lt;br /&gt;
MySQL :: MySQL 5.1 Reference Manual :: 21.1.5.2 Step-by-step Guide to Connecting to a MySQL Database through Connector/ODBC - http://dev.mysql.com/doc/refman/5.1/en/connector-odbc-examples-walkthrough.html&lt;br /&gt;
&lt;br /&gt;
== Check Tables ==&lt;br /&gt;
&lt;br /&gt;
MySQL :: MySQL 5.0 Reference Manual :: 4.5.3 mysqlcheck — A Table Maintenance Program - http://dev.mysql.com/doc/refman/5.0/en/mysqlcheck.html&lt;br /&gt;
&lt;br /&gt;
The mysqlcheck client performs table maintenance: It checks, repairs, optimizes, or analyzes tables.&lt;br /&gt;
&lt;br /&gt;
Each table is locked and therefore unavailable to other sessions while it is being processed, although for check operations, the table is locked with a READ lock only.&lt;br /&gt;
&lt;br /&gt;
mysqlcheck uses the SQL statements CHECK TABLE, REPAIR TABLE, ANALYZE TABLE, and OPTIMIZE TABLE in a convenient way for the user. It determines which statements to use for the operation you want to perform, and then sends the statements to the server to be executed.&lt;br /&gt;
&lt;br /&gt;
 mysqlcheck -A -e&lt;br /&gt;
&lt;br /&gt;
 mysqlcheck -c  --all-databases&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* Reindexing MySQL database : mysql, reindexing, database - http://www.experts-exchange.com/Database/MySQL/Q_21502908.html&lt;br /&gt;
&lt;br /&gt;
== Repair Tables ==&lt;br /&gt;
&lt;br /&gt;
That will help mysql make better choices about index usage.&lt;br /&gt;
 ANALYZE TABLE tablename;&lt;br /&gt;
&lt;br /&gt;
Use to defragment a table that had a large delete.&lt;br /&gt;
 OPTIMIZE TABLE tablename;&lt;br /&gt;
&lt;br /&gt;
Fixes corrupted tables/index.&lt;br /&gt;
 REPAIR TABLE tablename;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* Reindexing MySQL database : mysql, reindexing, database - http://www.experts-exchange.com/Database/MySQL/Q_21502908.html&lt;br /&gt;
&lt;br /&gt;
== Search for Three Letter Words ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;By default MediaWiki uses MySQL and the default FULLTEXT indexing uses built-in stop words and a minimum word length of four. A list of the stop words is available but are the usual thing (the, and, one_, etc.). You can set your own stop words by setting the ft_stopword_file system variable but the default stop words may be sufficient to your purposes. However, there are many three letter words which you may like to index (_SVN, RSS, FAQ, etc.). In order to do this you need to change the FULLTEXT indexing to a minimum word length of three. To do this edit the my.ini and add to the end of the [mysqld] section:&amp;quot; [http://kb.ucla.edu/articles/configuring-mediawiki-to-search-for-three-letter-words]&lt;br /&gt;
&lt;br /&gt;
 [mysqld]&lt;br /&gt;
 &lt;br /&gt;
 # Minimum word length to be indexed by the full text search index.&lt;br /&gt;
 # You might wish to decrease it if you need to search for shorter words.&lt;br /&gt;
 # Note that you need to rebuild your FULLTEXT index, after you have&lt;br /&gt;
 # modified this value.&lt;br /&gt;
 ft_min_word_len = 3&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Restart MySQL, and then reindex the relevant tables. The tables are ${mw_}searchindex where ${mw_} is the table prefix for the MediaWiki instance (there will be one searchindex table for each instance). To reindex the table, log into the server and start up MySQL Administrator. Log in as root and click Catalogs, then wikidb. Select the table and click the Maintenance button. Select Repair Tables and press Next. Check the Quick option under Repair Method and click Repair Tables. Repeat for each MediaWiki instance.&amp;quot; [http://kb.ucla.edu/articles/configuring-mediawiki-to-search-for-three-letter-words]&lt;br /&gt;
&lt;br /&gt;
Reindex table:&lt;br /&gt;
 use [database];&lt;br /&gt;
 ANALYZE TABLE searchindex;&lt;br /&gt;
 REPAIR TABLE searchindex;&lt;br /&gt;
 OPTIMIZE TABLE searchindex;&lt;br /&gt;
&lt;br /&gt;
== Show long running processess ==&lt;br /&gt;
&lt;br /&gt;
Notice &amp;quot;Time&amp;quot; field when running: [http://www.electrictoolbox.com/show-running-queries-mysql/]&lt;br /&gt;
 mysql&amp;gt; show processlist;&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; show full processlist\G&lt;br /&gt;
&lt;br /&gt;
== Minimal Memory Instance ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
performance_schema      = 0&lt;br /&gt;
&lt;br /&gt;
key_buffer              = 8M &lt;br /&gt;
max_connections         = 30 # Limit connections&lt;br /&gt;
query_cache_size        = 8M # try 4m if not enough &lt;br /&gt;
query_cache_limit       = 512K&lt;br /&gt;
thread_stack            = 128K&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or another option...&lt;br /&gt;
&lt;br /&gt;
 cp /etc/my.cnf /etc/my.cnf.orig&lt;br /&gt;
 cp /usr/share/mysql/config.small.ini /etc/my.cnf&lt;br /&gt;
&lt;br /&gt;
And give the instance a swap file:&lt;br /&gt;
&lt;br /&gt;
 SWAPFILE=/swapfile.swap&lt;br /&gt;
 dd if=/dev/zero of=$SWAPFILE bs=1M count=512&lt;br /&gt;
 mkswap $SWAPFILE&lt;br /&gt;
 swapon $SWAPFILE&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* Reducing memory consumption of mysql on ubuntu@aws micro instance - Stack Overflow - http://stackoverflow.com/questions/10676753/reducing-memory-consumption-of-mysql-on-ubuntuaws-micro-instance&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
Minimal: (based on [http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html])&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[client]&lt;br /&gt;
port            = 3306&lt;br /&gt;
socket          = /var/run/mysqld/mysqld.sock&lt;br /&gt;
&lt;br /&gt;
[mysqld_safe]&lt;br /&gt;
socket          = /var/run/mysqld/mysqld.sock&lt;br /&gt;
nice            = 0&lt;br /&gt;
&lt;br /&gt;
[mysqld]&lt;br /&gt;
user            = mysql&lt;br /&gt;
pid-file        = /var/run/mysqld/mysqld.pid&lt;br /&gt;
socket          = /var/run/mysqld/mysqld.sock&lt;br /&gt;
port            = 3306&lt;br /&gt;
basedir         = /usr&lt;br /&gt;
datadir         = /var/lib/mysql&lt;br /&gt;
tmpdir          = /tmp&lt;br /&gt;
lc-messages-dir = /usr/share/mysql&lt;br /&gt;
log_error       = /var/log/mysql/error.log&lt;br /&gt;
bind-address    = 127.0.0.1&lt;br /&gt;
skip-external-locking&lt;br /&gt;
&lt;br /&gt;
performance_schema      = 0&lt;br /&gt;
&lt;br /&gt;
innodb_buffer_pool_size=5M&lt;br /&gt;
innodb_log_buffer_size=256K&lt;br /&gt;
query_cache_size=0&lt;br /&gt;
max_connections=10&lt;br /&gt;
key_buffer_size=8&lt;br /&gt;
thread_cache_size=0&lt;br /&gt;
&lt;br /&gt;
thread_stack=131072&lt;br /&gt;
sort_buffer_size=32K&lt;br /&gt;
read_buffer_size=8200&lt;br /&gt;
read_rnd_buffer_size=8200&lt;br /&gt;
max_heap_table_size=16K&lt;br /&gt;
tmp_table_size=1K&lt;br /&gt;
bulk_insert_buffer_size=0&lt;br /&gt;
join_buffer_size=128&lt;br /&gt;
net_buffer_length=1K&lt;br /&gt;
&lt;br /&gt;
binlog_cache_size=4K&lt;br /&gt;
binlog_stmt_cache_size=4K&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
TODO See:&lt;br /&gt;
*  http://wiki.vpslink.com/Low_memory_MySQL_/_Apache_configurations&lt;br /&gt;
* http://www.narga.net/optimizing-apachephpmysql-low-memory-server/&lt;br /&gt;
&lt;br /&gt;
== Issues ==&lt;br /&gt;
&lt;br /&gt;
=== Key too long ===&lt;br /&gt;
Error:&lt;br /&gt;
 ERROR 1071 (42000) at line 774: Specified key was too long; max key length is 1000 bytes&lt;br /&gt;
&lt;br /&gt;
Line 744 shows the following:&lt;br /&gt;
 CREATE TABLE NXC_PAL_METER&lt;br /&gt;
 (&lt;br /&gt;
    ...&lt;br /&gt;
    ENTERPRISEID INT(11) NOT NULL DEFAULT 0,&lt;br /&gt;
    ...&lt;br /&gt;
    HOST VARCHAR(255),&lt;br /&gt;
    WEB VARCHAR(128),&lt;br /&gt;
    ...&lt;br /&gt;
    INDEX (ENTERPRISEID,HOST,WEB),&lt;br /&gt;
    ...&lt;br /&gt;
 );&lt;br /&gt;
&lt;br /&gt;
 11+180+128=394, which is less than 1000&lt;br /&gt;
&lt;br /&gt;
After researching this issue it was determined that the cause is the UTF-8 charset. UTF-8 uses 3 bytes for 1 character and latin uses 1 character [http://bugs.mysql.com/bug.php?id=4541].&lt;br /&gt;
&lt;br /&gt;
 latin1 = 1 byte = 1 chararcter&lt;br /&gt;
 uft8  = 3 byte = 1 chararcter&lt;br /&gt;
&lt;br /&gt;
 394*3=1182&lt;br /&gt;
&lt;br /&gt;
After reducing the host size from 255 to 180 the error went away. Martineau says that this code has been running on Palquad for months, and suggested letting the java code work it&amp;#039;s magic. After researching why it worked on Palquad, I found that the NXC_PAL_METER table does not have the index. The Java code must have created the table, but failed upon building the index.&lt;br /&gt;
&lt;br /&gt;
Reference:&lt;br /&gt;
*[http://bugs.mysql.com/bug.php?id=4541&lt;br /&gt;
&lt;br /&gt;
== keywords ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Database]]&lt;br /&gt;
[[Category:Web Development‎]]&lt;/div&gt;</summary>
		<author><name>Kenneth</name></author>
	</entry>
</feed>