我在Mac OS X Lion上,刚刚使用MacPorts安装了mysql5。
然后我成功地跑了:
sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
我可以启动服务器并以“根”连接,但是我不能创建任何数据库。
$ mysql5 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution
mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
我在google上做了很多尝试来解决这个问题,看起来问题可能与/opt/local/var/db/mysql5的文件系统权限有关,但是我尝试将这些更改为无效:
$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx 8 _mysql _mysql 272 Apr 12 11:55 mysql5
我曾尝试过拥有者是“mysql”、“mysql”和“root:wheel”,但没有一个有什么不同。
最佳答案
固定——MySQL创建了我的“根”帐户,没有特权(我是一个MySQL新手)。
我通过启动mysql解决了这个问题
--skip-grant-tables
然后启动:
mysql5
和运行:
mysql> UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> GRANT ALL ON *.* TO 'root'@'localhost';
希望这能帮助别人!