Project

General

Profile

MySQL Installation on Debian Etch

Installing MySQL

Currently, MySQL 5.0 is included within the stable release of Debian Etch. It can be installed easily with the following command line:

# apt-get install mysql-server

Installing the Python Interface to MySQL

In order to use MySQL within Python-scripts, the following package must be installed.

# apt-get install python-mysqldb

Installing the PHP Interface to MySQL

In order to use MySQL within PHP-scripts, the following package must be installed.

# apt-get install php5-mysql

Configuring MySQL

Create Administration Account

In order to get working with MySQL, at least on user (e.g. "root") acting as database administrator must be created in MySQL.

# mysqladmin -u root password 'secret'

Create Database

Usually, applications require an empty database for setup. An empty database (e.g. "emptyDB") can be created with the following command.

# mysqladmin -u root -p create emptyDB

Using the --password option, you will not be prompted for a password (replace secret with your password).

# mysqladmin -u root --password='secret' create emptyDB

Granting Access Rights to a Database

If you want to assign all access rights on a database (e.g. emptyDB) to the user root, enter the one of the following commands(the password option is also available for the mysql command):

# mysql -u root -p

or without password prompting

# mysql -u root --password='secret'

Then, a MySQL console opens where you should enter the following command.

GRANT ALL PRIVILEGES ON drupal.* TO root;

The answer should be

'Query OK, 0 rows affected'.

Now, activate the database and leave the MySQL console

flush privileges;
exit;

If you like to introduce an specific database administrator, you may add another user to MySQL and granting privileges to him, e.g.

# mysql -u root --password='secret'
GRANT ALL PRIVILEGES ON emptyDB.* TO emptyDB@localhost IDENTIFIED by 'secret';
'Query OK, 0 rows affected'.
flush privileges;
exit;

Backup Databases

In order to backup databases or tables, use one of the following_mysqldump_ command lines.

# mysqldump [options] db_name [tables]
# mysqldump [options] --databases db_name1 [db_name2 db_name3...]
# mysqldump [options] --all-databases

For instance, if you want to backup the database exampleDB completely, the following command line stores the database exampleDB into the SQL-script file named exampleDB.sql

# mysqldump -u root --password='secret' exampleDB > exampleDB.sql

Import Databases

Databases can be imported into MySQL by executing SQL-script files, formerly generated by a database backup or manually.

The following commands imports the database from the file exampleDB.sql into the exampleDB database.

# mysql -u root --password='secret' exampleDB < /root/bdtracker/exampleDB.sql;

Delete Databases

To delete databases from MySQL, use the DROP DATABASE within the MySQL console.

# mysql -u root --password='secret'
DROP DATABASE exampleDB;
'Query OK, 0 rows affected'.
exit;
Add picture from clipboard (Maximum size: 40 MB)