1 安装mysql
1. sudo apt-get install mysql-server
2. apt-get isntall mysql-client
3. sudo apt-get install libmysqlclient-dev 中间安装过程中会提示设置密码
4.sudo netstat -tap | grep mysql 通过上述命令检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功。
参考链接:https://www.cnblogs.com/zhuyp1015/p/3561470.html
2 忘记密码或者未初始化密码
1.利用mysql自带的用户debian-sys-maint进行重置密码,只有Debian或Ubuntu服务器才有,存在于/etc/mysql/debian.cnf文 件 中,使用文件中提供的用户名和密码进入mysql
mysql -u debian-sys-maint -p
use mysql;
update user set authentication_string=password('123456') where user='root';
2. 编辑mysqld.cnf文件
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
在文件中的skip-external-locking一行的下面添加一行:skip-grant-tables
sudo service mysql restart
终端输入mysql进入MySQL,输入USE mysql切换至mysql数据库
update mysql.user set authentication_string=password('123456') where user='root' ;
修改字段plugin
update user set plugin="mysql_native_password";
flush privileges;
参考链接:https://blog.csdn.net/xiamoyanyulrq/article/details/83041724
3 非root用户不能登入mysql
1、使用root用户登录mysql
2、添加具有本地(localhost/127.0.0.1)访问权限的用户
#create user 'test'@'localhost' identified by '123456';
3、创建具有远程访问权限的用户
#create user 'newuser'@'%' identified by '123456';
创建之后记得执行下面指令更新权限:
#flush privileges;
4、为新用户分配本地权限,可以指定数据库dbname和表名,可以用*替指所有。
#grant all privileges on `dbname`.* to 'test'@'localhost' identified by '123456';
5、为新用户分配远程权限,可以指定数据库dbname和表名,可以用*替指所有。
#grant all privileges on `dbname`.* to 'newuser'@'%' identified by 'password';
分配好之后之后记得执行下面指令更新权限:
#flush privileges;
6.在Ubuntu服务器下,MySQL默认是只允许本地登录,因此需要修改配置文件将地址绑定给注释掉:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1 #注释掉这一行就可以远程登录了
参考链接:https://blog.csdn.net/ljxfblog/article/details/80197277
https://blog.csdn.net/piaocoder/article/details/53704126
4 卸载mysql
首先用dpkg --list|grep mysql查看自己的mysql有哪些依赖
先卸载sudo apt-get remove mysql-common
然后:sudo apt-get autoremove --purge mysql-server-5.0
再用dpkg --list|grep mysql查看,还剩什么就卸载什么
最后清楚残留数据:dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
参考链接:https://blog.csdn.net/w3045872817/article/details/77334886