How To Import Mysql Database

Table of contents:

How To Import Mysql Database
How To Import Mysql Database

Video: How To Import Mysql Database

Video: How To Import Mysql Database
Video: MySQL Import Database using MySQL Workbench 2024, December
Anonim

The MySQL database management system is one of the most popular solutions for creating universal and flexible data storage services for web applications. Drivers for working with the MySQL DBMS are included in the overwhelming majority of modern CMS distributions. For most of the popular scripts and content management systems, there are databases with initial data filling. You only need to import the mysql database to get started.

How to import Mysql database
How to import Mysql database

Necessary

  • - authorization data for access to the MySQL server;
  • - console client mysql.

Instructions

Step 1

Prepare a MySQL database dump file. If the dump is in an archive, unpack it. Use an appropriate unpacker or file manager capabilities.

Step 2

Determine the encoding of the base dump text if it is not known in advance. Open the file in an editor or viewer that allows dynamic encoding changes. Choose the encoding of the document.

Step 3

Connect to MySQL server. Run the mysql client program from the console with the specified hostname and username. The hostname is specified using the -h command line option, and the username is specified using the -u option. You can also specify a password on the command line to access the server using the --password switch, or leave this parameter unchecked (then the password will be prompted for when connecting). Enter the following command in the console:

mysql -h HostName -u UserName --password = UserPassword

and press the Enter key. Here HostName is the hostname (it can be either symbolic or an IP address), UserName is the DBMS username, and UserPassword is the password. If the connection is successful, a message will be displayed in the console, as well as a command prompt.

Step 4

List the character sets supported by the server. Enter "SHOW CHARACTER SET;" in the console. Hit Enter. Determine if the server has a character set that matches the encoding that contains the dump data of the imported database.

Step 5

Display a list of existing databases. Enter "SHOW DATABASES;" in the console. Hit Enter.

Step 6

Create a new database on MySQL server. Enter a command like:

CREATE DATABASE `DatabaseName` CHARACTER SET CharsetName COLLATE CollateName;

and press Enter. Specify the desired database name for the DatabaseName parameter. It must not match any of the names in the list displayed in step five. For the CharsetName parameter, specify the name of the character set that matches the encoding of the database dump text. The list of character sets was displayed in the fourth step. Replace CollateName with the value from the "Default collation" field of the corresponding line in the same list.

Step 7

Disconnect from the server. Enter q in the console. Hit Enter.

Step 8

Import the MySQL database. Enter a command like this in the console:

mysql -h HostName -u UserName -D DatabaseName -b -B -s -p <filename

press Enter. Enter the user password. Hit Enter. Wait until the data is imported. Here the values of the -h and -u parameters are the same as described in the third step. Instead of DatabaseName, you must substitute the name of the database created in the sixth step. Filename must be the full or relative path to the database dump file. Error messages will be printed to the console.

Recommended: