(1)、安装数据库
sudo apt install -y mysql-server mysql-client
(2)、开启数据库服务
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)连接数据库
mysql -hloaclhost -uroot -p123456 -P3306
- -h : host(ip地址) localhost = 127.0.0.1
- -u : username(⽤⼾账⼾)
- -p : password(密码)
- -P : port(端⼝, 默认端⼝3306)
备注: 第⼀次使⽤ root 连接后最好添加⼀个新的⽤⼾来操 作。出于安全考虑,⽇常开发中最好不要使⽤ root。 root⽤⼾⼀般是管理员使⽤的。
- 创建新⽤⼾
-- *.* 代表该⽤⼾可以操作任何库、任何表
-- 主机名可以使⽤ '%', 代表允许该⽤⼾从任何机器登陆
GRANT ALL PRIVILEGES on *.* to '⽤⼾名'@'主机' IDENTIFIED BY "密码" WITH GRANT OPTION;
-- 刷新使权限⽣效
flush privileges;
(4)、退出数据库
- exit
- quit
- \q
- 快捷键: ctrl + d
(5)密码忘记
1.打开配置:
vim /etc/my.cnf
2.添加这么⼀段:
[mysqld] skip-grant-tables
3.修改完成后,保存退出,重启服务:
sudo systemctl restart mysqld