(1), installation of the database
sudo apt install -y mysql-server mysql-client
(2), open the database service
1. Ubuntu : service mysql start|stop|restart|status
2. Deepin : systemctl start|stop|restart|status mysqld
3. CentOS7 : systemctl start|stop|restart|status mysqld
4. CentOS6 : service mysqld start|stop|restart|status
(3) connecting to the database
mysql -hloaclhost -uroot -p123456 -P3306
- -h: host (ip address) localhost = 127.0.0.1
- -u : username(⽤⼾账⼾)
- -p: password (password)
- -P: port (end-connector, the default end-connector 3306)
Note: Using the First Time After connecting the best root Add an new Use ⼾ to operate. For security reasons, the date often develop best Do not use root. Using ⼾ shoots as usual root is the administrator of Use.
- Creating a new Use ⼾
-- *.* 代表该⽤⼾可以操作任何库、任何表
-- 主机名可以使⽤ '%', 代表允许该⽤⼾从任何机器登陆
GRANT ALL PRIVILEGES on *.* to '⽤⼾名'@'主机' IDENTIFIED BY "密码" WITH GRANT OPTION;
-- 刷新使权限⽣效
flush privileges;
(4) to exit the database
- exit
- quit
- \q
- Shortcuts: ctrl + d
(5) Password Forgot
1. Open the configuration:
vim /etc/my.cnf
2. Add so one Hash:
[mysqld] skip-grant-tables
3. After editing, save and exit and restart the service:
sudo systemctl restart mysqld