MySQL initialization in Windows environment

Source: Internet
Author: User
Tags root directory

Linux environment, after the installation of MySQL, you can not start the service directly, you must first initialize the database. The main tasks of initialization include:

Initialization of the log, table space and other databases must file;

Create and initialize the system database (MySQL).

When the initialization is complete, the mysqld daemon is started before the database can be accessed.

In the Windows environment, the installation package has a good initialization environment, installed in the MySQL root directory after the data subdirectory. So there is no need for manual initialization. However, in some cases, you may also need to initialize the database from scratch, such as:

Data files are corrupted and need to be rebuilt;

Hope to preserve the existing environment and establish a new environment;

Hope to establish a clean environment.

Unfortunately, the Linux environment uses the mysql_install_db.sh script to initialize the database environment, and no script is provided in the Windows version. So what should we do?

After analyzing the mysql_install_db.sh in Linux environment, it is found that the commands for initializing the database are mainly 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"
......

which

$create _System_Tables, $fill _system_tables and $fill_help_tables are the creation of system databases, initialization of data in system databases, and initialization of help data;

$filter _cmd_line is to filter out the host name (used to cross initialize the database environment of the non-native machine, can be ignored);

$mysqld _install_cmd_line is mainly "mysqld--bootstrap" order;

Analysis of the above content, you can manually initialize the database. The specific steps are as follows:

Set the MySQL configuration file. The main is to set the Basedir (MySQL home directory, such as:/opt/mysql-5.1.40) and DataDir (database file directory, such as:/var/db/mysql) two parameters.

Initialize the database directory, check that the/var/db/mysql and/var/db/mysql/mysql (System database) directories exist, and create them manually if they do not exist.

Prepares the SQL script for initializing the database. Copy the Mysql_system_tables.sql, Mysql_system_tables_data.sql, and fill_help_tables.sql three files in the/opt/mysql-5.1.40/share directory to/ TMP directory, and at the very beginning of each file insert "use MySQL;" Line.

Initialize the database by executing the following command:

/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 to 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, and verify that the database is normal. (www.3lian.com)

The database has already been initialized and can be accessed normally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.