1. Install to linux
1. Install mysql-server
1. Check whether mysql has been installed in the system before installation
ls /usr/share
2. Install mysql-server
sudo apt-get install mysql-server
3. Check again and find that there is an extra mysql
ls /usr/share | grep mysql //在ls打印结果中搜索mysql关键字
4. Login
When creating mysql, the system creates an administrator account password by default
sudo cat /etc/mysql/debian.cnf
Log in with an administrator account:
mysql -u debian-sys-maint -p //执行后输入密码
2. View mysql status
The following two commands have the same effect
sudo service mysql stauts
systemctl status mysql.service
3. Basic use of MySQL database
- Start the MySQL database service
sudo service mysql start
或
sudo systemctl start mysql.service
- Restart the MySQL database service
sudo service mysql restart
或
sudo systemctl restart mysql.service
- Stop the MySQL database service
sudo service mysql stop
或
sudo systemctl stop mysql.service
- View MySQL running status
sudo service mysql status
或
sudo systemctl status mysql.service
- Set the MySQL service to start automatically
sudo service mysql enable
或
sudo systemctl enable mysql.service
- Stop the MySQL service from starting at boot
sudo service mysql disable
或
sudo systemctl disable mysql.service
- MySQL configuration file
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
4. Update the root password
set password for root@localhost = password('123');
# alter user 'root'@'localhost' identified by '123';//上面的方法如果无效,尝试下这个
2. Install to Docker
1. Obtain the image
docker pull mysql:5.7
2. Run the container (configure musql password: 123123)
docker run -d -p 3310:3306 \
-v /home/mysql/conf:/etc/mysql/conf.d \
-v /home/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123123 \
--name mysql01 \
mysql:5.7
-d 后台运行
-v 挂载
-e 环境配置
3. View container information
docker ps //看到mysql01已经启动
Three, install to window
Please refer to this tutorial: http://c.biancheng.net/view/2412.html
Fourth, connect to the mysql database
1. Login via command line
- If on linux, install
sudo apt-get install mysql-clinet
; - If it is on the window, install mysql first, then enter: , and add the bin
系统 > 高级系统设置 > 系统变量 > PATH
directory under the mysql installation directory .
Execute the connection command:
mysql -u root -h 【mysql服务ip地址】 -P 【mysql服务端口】 -p
//输入密码后,就能登录
2. Client login
There are many interface-based mysql clients on windows, and the operation of mysql is very simple. For example: navigate, SQLyog, phpmyadmin.
5. Uninstall mysql
1. Uninstall from linux
sudo apt-get remove mysql-server
sudo apt-get autoremove
Check it after execution and find that mysql is gone
2. Uninstall from Docker
Then stop/delete the corresponding container directly.
recommended reading
Ubuntu installation and use of MySQL
Mysql common commands detailed Daquan
MySql download address