1.使用skip-grant-tables跳过密码验证
修改mysql安装根目录my.in文件,修改完成重启nysql服务。
2.免密进入mysql
3.添加root用户(超级用户)
use mysql;
--添加用户
insert into user set user = 'root', ssl_cipher = '',x509_issuer='',x509_subject='';
--设置用户权限(以下包含所有权限,为超级用户)
update user set Host='localhost',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',event_priv='y',trigger_priv='y',create_tablespace_priv='y' where user='root';
4.修改密码
--设置密码
update user
set plugin="mysql_native_password",authentication_string=password('123456')
where user="root";
--应用修改
FLUSH PRIVILEGES;
5.取消my.in跳过密码验证修改,重启服务,连接mysql服务
6.创建用户语句
--所有权限,本地,用户名root,密码123456
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
grant all on *.* to root@localhost identified by '123456' with grant option;
--无权限,本地,只支持登录
GRANT USAGE ON *.* TO 'test'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;