安装
sudo apt-get install mysql-server mysql-client
然后按照提示输入
![](https://img.haomeiwen.com/i9921373/1006e29da7f20da8.png)
![](https://img.haomeiwen.com/i9921373/32e9488d476b58d0.png)
卸载
1.删除mysql
sudoapt-get remove mysql-*
然后按照提示输入
2.清理残留的数据
dpkg-l|grep ^rc|awk'{print $2}'|sudoxargs dpkg -P
管理服务
启动
service mysql start
停止
service mysql stop
重启
service mysql restart
允许远程连接
找到mysql配置文件并修改
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
将 bind-address=127.0.0.1 注释掉
![](https://img.haomeiwen.com/i9921373/fc4dfe5d9ba6aa04.png)
登录mysql,运行命令
mysql -hlocalhost -uroot -p
会提示输入密码
![](https://img.haomeiwen.com/i9921373/524ecf3bd74871a4.png)
执行数据库语句
第一句话:grant all privileges on *.* to 'root'@'%' identified by 'mysql' with grant option;
第二句话:flush privileges;
mysql> grant all privileges on . to ‘root’@’%’ identified by ‘密码’;
mysql> flush privileges;
登陆之后 quit或者exit退出mysql
重启虚拟机
补充:
当然登陆还有加长的写法。(一般用于shell编程,参数更直观)
mysql --host=localhost --user=root --password --port=3306
![](https://img.haomeiwen.com/i9921373/c4f304461cbc410c.png)
网友评论