MySQL Tidbits

After installing mysql-server on Fedora 15:

# chkconfig mysqld on
# service mysqld start
# mysql_secure_installation

For the firewall, secure port 3306.

After starting the database server mysqld, it's now time to create a database, table, add data, and a user with full permissions using the client, mysql:
# mysql -u root -p
mysql> CREATE DATABASE mydb;
mysql> USE mydb;
mysql> CREATE TABLE questions (
> question TEXT);
mysql> INSERT INTO questions VALUES (0,"Who created Linux?");
mysql> GRANT ALL ON mydb.* TO 'dbuser'@'localhost' IDENTIFIED BY 'password';

To backup a MySQL database, use the mysqldump command:

mysqldump -u root -p mydb > mydb.db

To restore a MySQL database, first drop the database, then create the database and use mysql to restore it:

mysql -u root -p

mysql> drop database mydb;
Query OK, 15 rows affected (1.85 sec)

mysql> create database mydb;
Query OK, 1 row affected (0.00 sec)

mysql> quit

mysql -u root -p mydb < mydb.db


No comments:

About Me - WrightRocket

My photo

I've worked with computers for over 30 years, programming, administering, using and building them from scratch.

I'm an instructor for technical computer courses, an editor and developer of training manuals, and an Android developer.