Initialize mysql in Windows and mysql in windows
In Linux, after mysql is installed, the service cannot be started directly. You must initialize the database first. Initialization mainly includes:
- Initialize required files for logs, tablespaces, and other databases;
- Create and initialize the system database (mysql ).
After initialization, start the mysqld daemon to access the database. In Windows, the installation package contains an initialized environment, which is displayed in the data subdirectory of the mysql root directory. Therefore, manual Initialization is not required. However, in some cases, you may need to initialize the database from scratch, for example:
- Data files are damaged and need to be rebuilt;
- We hope to keep the existing environment unchanged and create a new environment;
- We hope to build a clean environment.
Unfortunately, in Linux, The mysql_install_db.sh script is used to initialize the database environment. In windows, the script is not provided. So what should we do? After analyzing mysql_install_db.sh in Linux, we found that the commands used to initialize the database are mainly the following:
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/nullthen 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 are used to create a system database, initialize data in the system database, and initialize help data;
- $ Filter_cmd_line is used to filter out the Host Name (for cross-initialization of non-local running database environments, which can be ignored );
- $ Mysqld_install_cmd_line is mainly the "mysqld -- bootstrap" command;
After analyzing the above content, you can manually initialize the database. The procedure is as follows: the database has been initialized and can be accessed normally.