Install mysql and import and export on ubuntu

Install mysql on ubuntu:   

1. sudo apt-get install mysql-server   
2. apt-get isntall mysql-client
3. sudo apt-get install libmysqlclient-dev

After installing mysql, check whether the installation is successful: sudo netstat -tap | grep After the mysql

check is successful, that is to do a simple test
mysql -u root -p 

and other operation commands are the same as usual.

The following mainly talks about how to export database files and import database files:

1. Use the mysqldump command to export the database (note the installation path of mysql, that is, the path of this command):
1. Export data and table structure:
mysqldump -u username -p password database name > database name.sql
$/usr/mysqldump - uroot -p abc > abc.sql
will prompt for a password after hitting Enter

\

\

\

2. Only export the table structure
mysqldump -u username -p password -d database name > database
name.sql $/usr/ mysqldump -uroot -p -d abc > abc.sql

Note: /usr/ ---> data directory of mysql

Second, import the database
1, first create an empty database
mysql>create database abc;

2. Method 1 of importing database
:
(1) Select database
mysql>use abc;
(2) Set database code
mysql>set names utf8;
(3) Import data (pay attention to the path of sql file)
mysql>source /home/abc/abc .sql;
Method 2:
mysql -u username -p password database name < database
name.sql #mysql -uabc_f -p abc < abc.sql

\\

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325767971&siteId=291194637