先删掉/var/lib/mysql下面的文件,然后初始化数据库mysqld --initialize
先停掉mysql,然后在/etc/mysql/my.cnf文件中添加以下内容
之后就可以直接用mysql -uroot -p直接回车不输入密码回车进入数据,然后执行命令修改密码的:update mysql.user set authentication_string=password('新密码') where user='root' and Host ='localhost';
登陆进去后会要求再次修改密码,执行命令:alter user 'root'@'localhost' identified by '新密码';
允许用户远程登陆:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Ceshi123' WITH GRANT OPTION;
更新权限:flush privileges;