What is MySQL? How to Initialize the MySQL?

MySQL is a small relational database management system that developed by MySQL AB company which is based in Sweden. SQL relational database data is stored in the database objects called tables, rather than all data on a large warehouse. This increases the speed and flexibility.

In the Linux environment, you cannot directly start the service also after installed mysql, you must first initialize the database. Initialization work including:

After doing the analysis of mysql_install_db.sh under the Linux environment, you need to initialize the database, and the command to initialize the database is the following lines:

mysql_install_db.sh

??#?Pipe?mysql_system_tables.sql?to?”mysqld?–bootstrap”

??s_echo?”Installing?MySQL?system?tables…”

??if?{?echo?”use?mysql;”;?cat?$create_system_tables?$fill_system_tables;?}?|?eval?”$filter_cmd_line”?|?$mysqld_install_cmd_line?>?/dev/null

??then

??s_echo?”OK”

??s_echo?”Filling?help?tables…”

??#?Pipe?fill_help_tables.sql?to?”mysqld?–bootstrap”

??if?{?echo?”use?mysql;”;?cat?$fill_help_tables;?}?|?$mysqld_install_cmd_line?>?/dev/null

??then

??s_echo?”OK”

Where:

$ create_system_tables, $ fill_system_tables and $ fill_help_tables is respectively to create the system database, initialize the data in the system database, and initialize the help data.

The $ filter_cmd_line filter out the host name (for cross initialization of the machine running the database environment and can be ignored);
The $ mysqld_install_cmd_line is “mysqld – bootstrap” command;

If you knew well about the above analysis then you can manually initialize the database. Speific steps are as follows:
Set the mysql configuration file. To set basedir (mysql home directory of :/ opt/mysql-5.1.40) and datadir (the database file directory, such as the two parameters :/ the var / db / MySQL).

Initialize the database directory, check if the / var / db / mysql and / var / db / mysql / mysql (system database) directory exists, otherwise, manually create it.

Prepare the script for initializing the database sql. Get mysql_system_tables.sql mysql_system_tables_data.sql and fill_help_tables.sql three files which under /Opt/mysql-5.1.40/share directory copied to the /tmp directory, and in the beginning of each file insert into the “use mysql;” command.

Run the following command to initialize the database:

/ Opt/mysql-5.1.40/bin/mysqld.exe – bootstrap – console </ tmp / mysql_system_tables.sql

/ Opt/mysql-5.1.40/bin/mysqld.exe – bootstrap – console </ tmp / mysql_system_tables_data.sql

/ Opt/mysql-5.1.40/bin/mysqld.exe – bootstrap – console </ tmp / fill_help_tables.sql

Run / opt/mysql-5.1.40/bin/mysqld.exe, start the database service (Note: the command to stop the database service is / opt/mysql-5.1.40/bin/mysqladmin.exe-uroot shutdown).

Run / opt/mysql-5.1.40/bin/mysql.exe-uroot, access the database service, verify if the database is fine.

Initialize log, tablespace of the database which are necessary;

Create and initialize the system database (mysql).

When initialization is completed, start the daemon of mysql process before access to the database.

In the Windows environment, the installation package comes with an initialization good environment, expand the data subdirectory in the mysql root directory after installation. So do not need to be initialized manually. However, under certain circumstances, also may need to initialize the database from scratch, such as:

Data file is damaged and needs to be rebuilt;

Wish to retain the existing environment, establish a new environment;

Hope to create a clean environment;

At this point the database has been initialized, can be a normal visit.

Published by Tony Shepherd & last updated on May 30, 2013 7:36 am

Leave a Reply