linux平台中mysql 的root用户 默认是没密码的。我想增加一个密码,在网上查了人家说使用
mysql>UPDATE user SET password=PASSWORD(‘new_password’) WHERE user=’root’;
mysql>FLUSH PRIVILEGES;
我按照上面的命令输入,不但root密码没有 就连数据库都没有了,而且建立数据库的时候
Access denied for user ''@'localhost' to database 'safemedia'报错不知道各位大侠有什么方法没有,今天弄了一天了 有点急了。,

解决方案 »

  1.   

    Access denied for user ''@'localhost' to database 'safemedia'报错显然你没有使用ROOT登录啊。
    重新试一下mysql -uroot 
      

  2.   

    是以root 的用户登录的
    [root@SafeMedia ~]# mysql -uroot
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5
    Server version: 5.0.77 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema | 
    | test               | 
    +--------------------+
    2 rows in set (0.01 sec)mysql> create database sefamedia;
    ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'sefamedia'
      

  3.   

    很奇怪,MYSQL没有识别这个ROOT。按下面方法试一下。
    参考下贴三楼
    http://topic.csdn.net/u/20090515/21/2b3c9a12-d8a5-4bb1-9895-6069cef5aef8.html
      

  4.   

    我这个是Linux中的呀,不是Window上的。
      

  5.   

    那个贴子的第一部分就是 LINUX的,另外方法也一样,加同样的参数。
      

  6.   

    先停掉你的 MYSQL
    然后用--skip-grant-tables 启动。再mysql -u root mysql  进去。
      

  7.   


    mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  
      

  8.   

    我按照上面的命令输入,---------你输入了什么密码?我假设它是"123",那么用命令:mysql -uroot -p123-p123   表示输入root密码123然后用命令   status;show databases;    查看你是不是root登录成功了。
    我猜你改密码成功了。
      

  9.   

    把mysql的用户和权限,恢复成安装后的初始状态方法:
    1 停止数据库
    2 把mysql目录中的user.frm user.myd user.myi 这三个文件复制到test这个目录。
    3 运行mysql
    4 查看一下:(原有用户名是否都在)use test;select user,host,password from user;
    5 清空密码 update user set password='' where user='root';
    6 命令成功后,停止数据库,把那3个文件复制回mysql目录去,覆盖原文件。重启数据库,成功!
      

  10.   

    使用mysqld --skip-grant-tables来重新启动mysql,然后再修改密码。
      

  11.   

    mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
    mysql -u root mysql
    update user set password = PASSWORD('123456') where user='root';
    FLUSH PRIVILEGES;
    quit
    mysqld stop