Open and connected [database] MySQL-Linux database

(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
  1. -h: host (ip address) localhost = 127.0.0.1
  2. -u : username(⽤⼾账⼾)
  3. -p: password (password)
  4. -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

  1. exit
  2. quit
  3. \q
  4. 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
Published 116 original articles · won praise 10 · views 1351

Guess you like

Origin blog.csdn.net/weixin_44727383/article/details/104999479