问题
Ubuntu18.04 安装mysql(5.7)时没有提示设置root密码,装完怎么登录呢?
解决
找到初始账号和密码
sudo cat /etc/mysql/debian.cnf添加账号并设置密码
mysql -u debian-sys-maint -p
输入第1步查到的密码
创建本地访问用户
create user wcf@localhost identified by '123456';
创建任意ip访问用户
create user 'wcf'@'%' identified by '123456';
修改用户密码
set password for wcf@localhost = password('wcf')
本地连接授权,<dbname>的所有权限
grant all privileges on dbname.* to wcf@localhost identified by '123456';
所有连接授权,<dbname>的所有权限
grant all privileges on dbname.* to 'wcf'@'%' identified by 'wcf';
刷新权限
flush privileges;
- 如有必要,删掉原来的账号