我的系统是Ubuntu8.04,在MySQL的官方网站上下载mysql-server-5.0_5.0.21-3ubuntu1_i386.deb,安装之后系统没有提示我设置root帐号的密码。
现在不知道如何登录MySQL了,期待好心人的帮忙,谢谢!

解决方案 »

  1.   

    进入mysql的安装路径下,运行mysql -uroot -p,就能进入了,初始时密码为空(前提要把mysql服务启动)
      

  2.   

    我进入了/usr/share/mysql执行mysql -uroot -p好像不行:
    root@wantianwen-desktop:/usr/share/mysql# mysql -uroot -p
    Enter password: 
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    root@wantianwen-desktop:/usr/share/mysql# mysql -uroot -p
    Enter password: 
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
      

  3.   

    /etc/my.cnf中的[mysqld]部分添加: skip-grant-table
    重启mysql服务(或者重启机器)后,就可以不用密码进入mysql
      

  4.   


    用这种方法的确进入了MySQL,发现mysql.user表中没有root用户,我现在运行这个语句出错:
    mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123' WITH GRANT OPTION;
    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
      

  5.   

    我又用另外一种方法:向mysql.user表中插入了一条记录(超级用户),如下:
    INSERT INTO user VALUES('%','root','123','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);然后去掉了my.cnf中的skip-grant-table,重启MySQL,登录的时候还是报错:
    root@wantianwen-desktop:/home/wantianwen# mysql -uroot -p123
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
      

  6.   


    上面密码忘记加密了,Sql语句应该是这样的:
    INSERT INTO user VALUES('%','root',PASSWORD('123'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
    再次感谢 ydage 的帮助。