Initializing MySQL in the Windows environment

Source: Internet
Author: User

Linux environment, after installing MySQL, not directly start the service, you must first initialize the database. The main tasks of initialization include:
    • Initialize the files required for the database such as log, tablespace, etc;
    • Create and initialize the system database (MySQL).
After initialization is complete, the mysqld daemon is started before the database can be accessed. In the Windows environment, the installation package has an initialized environment in it, and after installation, expand the data subdirectory in the MySQL root directory. So it doesn't have to be initialized manually. However, in some cases, it may also be necessary to initialize the database from scratch, such as:
    • Data files are destroyed and need to be rebuilt;
    • Wishing to preserve the existing environment and create a new environment;
    • Want to build a clean environment.
Unfortunately, the Linux environment uses the mysql_install_db.sh script to initialize the database environment, and the script is not available in Windows edition. So what should we do? After analyzing the mysql_install_db.sh in Linux environment, it is found that the command of initializing database is 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 the system database, and initialization of help data;
    • $filter _cmd_line is to filter out the host name (for cross-initializing non-native running database environment, can be ignored);
    • $mysqld _install_cmd_line is mainly "mysqld--bootstrap" command;
By analyzing the above, you can manually initialize the database yourself. The steps are as follows:
    1. Set up the MySQL configuration file. The main is set Basedir (MySQL home directory, such as:/opt/mysql-5.1.40) and DataDir (database file directory, such as:/var/db/mysql) two parameters.
    2. Initializes the database directory, checks whether the/var/db/mysql and/var/db/mysql/mysql (System database) directories exist, and manually creates them if they do not exist.
    3. Prepares the SQL script to initialize 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/ The TMP directory, and at the very beginning of each file, insert "use MySQL;" Line.
    4. 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
    5. 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).
    6. Run/opt/mysql-5.1.40/bin/mysql.exe-uroot, access the database service, and verify that the database is healthy.
Now that the database has been initialized, you can access it normally.

Initializing MySQL in the Windows environment

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.