Ubuntu simply install MySQL with apt
The installation method through apt is very simple.
First put an installed picture. The
first step is to update the source.
apt-get update
Install mysql-server:
apt-get install mysql-server
Then the password configuration interface will appear, add the mysql administrator password, and continue the installation after entering it.
If it prompts that there is insufficient dependency during the installation process, run the following command:
apt-get install -f
After the installation is complete, you can view the mysql-related files.
Configuration file directory:
/etc/mysql/ (my.cnf) | /usr/share/mysql(命令和配置文件)
Database directory:
/var/lib/mysql
Check whether the service is started, service start and stop commands and start status.
$ netstat -anp | grep mysql
$ service mysql start
$ service mysql stop
$ service mysql status
$Connect to database
$ mysql -uroot -p123456
ps: To demonstrate, my password is simple 123456, hope you will not be so simple
note is written on the back -p password, no spaces
$ -h is the remote IP, -P is the port number, -u is the user name, -p is the password
At this step, the installation of MySQL is completed
Next is
backup database
View the name of the MySQL database we need to back up in our old server
The blog database is the one I want to back up,
then the \q command exits MySQL
In the root directory, create a folder to install the backup database
mkdir mysqlbackup
The command to back up the database is
mysqldump -uroot -p123456 blog >/root/mysqlbackup/blog.sql
Replace the name of the blog database above and the name of the generated database (blog.sql) by yourself
Then transfer the database to the newly installed server
Restore database
Next
, when you enter the new server, you will see the blog.sql file we just backed up in the root directory of the new server.
To backup,
first enter the MySQL of the new server
Then create the name of the database you want to restore later
create database newblog;
Then go back to the terminal
Start to restore data
mysql -uroot -p123456 newblog < blog.sql
The data is successfully returned