Difference between revisions of "Mysql"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
Line 86: Line 86:
 
== show users ==
 
== show users ==
 
  select User from mysql.user;
 
  select User from mysql.user;
 +
 +
== set password ==
 +
Here is how to set a password for a mysql user, in this example mythtv:
 +
set password for 'mythtv'@'localhost' = PASSWORD ('mythtv');
  
 
= See also =
 
= See also =
 
* [http://man-wiki.net/index.php/1:mysql man page of the command mysql, the command to connect to the database mysql]
 
* [http://man-wiki.net/index.php/1:mysql man page of the command mysql, the command to connect to the database mysql]

Revision as of 14:47, 10 December 2011

MySQL is a free database. This article describes how to install it, start it and how to connect to it. It has been tested with SUSE Linux 11.1 but should work with any Linux.

How to install mysql

sudo /sbin/yast -i mysql

How to start the database

sudo /etc/init.d/mysql start

How to connect to mysql

mysql

How to work with mysql

Here is a short example how to work with mysql, including an SQL statement:

$ mysql                                                                                                                                   
Welcome to the MySQL monitor.  Commands end with ; or \g.                                                                                                     
Your MySQL connection id is 1                                                                                                                                 
Server version: 5.0.67 SUSE MySQL RPM                                                                                                                         

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| mysql              | 
| test               | 
+--------------------+
3 rows in set (0.01 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| proc                      |
| procs_priv                |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
17 rows in set (0.00 sec)

mysql> desc time_zone;
+------------------+------------------+------+-----+---------+----------------+
| Field            | Type             | Null | Key | Default | Extra          |
+------------------+------------------+------+-----+---------+----------------+
| Time_zone_id     | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| Use_leap_seconds | enum('Y','N')    | NO   |     | N       |                |
+------------------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> select * from time_zone;
Empty set (0.00 sec)

mysql>

backup

create:

mysqldump <database> -h <host> -u <user> -p > dump.sql

for all databases

mysqldump --all-databases --user=root -p | gzip > all_databases.sql.gz

restore:

mysql <database> -h <host> -u <user> -p < dump.sql

show users

select User from mysql.user;

set password

Here is how to set a password for a mysql user, in this example mythtv:

set password for 'mythtv'@'localhost' = PASSWORD ('mythtv');

See also