apt-get update //更新软件资源
apt-get install mysql-server //安装MYSQL
sudo mysql secure installation //初始化配置(一定要注意看密码,不能无脑回车)
1.找到MYSQL配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
2.设置允许无密码登录
在[mysqld]中添加skip-grant-tables
(vim基础操作,vim进去文件后按 i 编辑,编辑完后按esc退出,shift + ;(冒号),wq退出并保存。)
3.重启MYSQL服务
service mysql restart
mysql -u root
use mysql;
2.查看user中的用户及权限
select user,host from user;
此时,若发现user列中没有root用户,表明在安装MYSQL时,没有进行初始化配置,需要手动添加root用户,给与权限;
若有root用户,直接重置root用户密码即可;
添加root用户:
insert into user(User,authentication_string,ssl_cipher,x509_issuer,x509_subject) values(‘root’,’’,’’,’’,’’);
添加权限(复制即可):
update user set Host=’%’,select_priv=‘y’, insert_priv=‘y’,update_priv=‘y’,Alter_priv=‘y’,delete_priv=‘y’,create_priv=‘y’,drop_priv=‘y’,reload_priv=‘y’,shutdown_priv=‘y’,Process_priv=‘y’,file_priv=‘y’,grant_priv=‘y’,References_priv=‘y’,index_priv=‘y’,create_user_priv=‘y’,show_db_priv=‘y’,super_priv=‘y’,create_tmp_table_priv=‘y’,Lock_tables_priv=‘y’,execute_priv=‘y’,repl_slave_priv=‘y’,repl_client_priv=‘y’,create_view_priv=‘y’,show_view_priv=‘y’,create_routine_priv=‘y’,alter_routine_priv=‘y’,create_user_priv=‘y’ where user=‘root’;commit;
设置root用户密码:
alter user ‘root’@’%’ identified with mysql_native_password by ‘你的密码’;
注意:密码格式必须符合要求,不然会报错的。mysql8貌似是要求必须包括大小写,数字和特殊字符。
最后注释配置文件中的跳过登陆验证,重启mysql即可。
##最后,如果出现这个错误,
ERROR 1356 (HY000): View ‘information_schema.COLUMNS’ references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
ERROR 1356 (HY000): View ‘information_schema.SCHEMATA’ references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
参考如下做法:
进入MYSQL
依次执行:
use mysql;
select * from user where User =‘mysql.infoschema’;
update user set Select_priv = ‘Y’ where User = ‘mysql.infoschema’;
flush privileges;
mysql -u root -p
use mysql;
刷新权限
flush privileges;
允许所有IP访问:
//找到 bind-address 修改值为 0.0.0.0(如果需要远程访问)
vi /etc/mysql/mysql.conf.d/mysqld.cnf
重启mysql
sudo service mysql restart
完全卸载mysql:
1.查看依赖
dpkg --list|grep mysql
2.开始卸载
sudo apt-get remove mysql-common
sudo apt-get autoremove --purge mysql-server-8.0
3.再次查看
dpkg --list|grep mysql
4.剩什么再次卸载什么
5.清除卸载残留
dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P