在亚马逊的Tokyo Region使用了个AWS EC2。
安装了Ubuntu 11.10的AMI之后,按照惯例安装各种软件, apache2.2, Mysql5.1。
在安装号mysqld启动的时候,发现如下错误:
[ERROR] Fatal error: Can't change to run as user 'mysql' ; Please check that the user exists!
原因:
在/etc/mysql/my.cnf的配置文件中,
#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
原来mysql server在启动的时候使用了mysql作为linux用户。
我们可以把配置文件中的 user=mysql 中的mysql改为当前我们正在使用的用户,比如我目前在用ubuntu用户, 这样就能解决问题。
当然还有另外一种办法。
我们先看看mysql这个用户到底在不在。
使用groups命令查看:
groups
ubuntu adm dialout cdrom floppy audio dip video plugdev netdev admin
很明显,不在嘛!
那我们就添加进去。
sudo groupadd -g 315 mysql
sudo useradd -u 315 -g mysql -d /var/lib/mysql -M mysql
启动mysql,sudo mysqld start。
但是又报错啦:
111210 13:24:46 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
111210 13:24:46 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
以上错误透露如下信息:
1.提示表不存在"Table 'mysql.plugin' doesn't exist"
2.可能是没有执行 mysql_install_db - u mysql 或 mysql_upgrade创建初始mysql数据库
而且启动选项中多了一个不支持的选项--skip-federated
那我们就执行下如下命令,看能否解决上述问题:
sudo mysql_install_db --user=mysql --datadir=/var/lib/mysql
Neither host 'ip-10-146-22-118' nor 'localhost' could be looked up with
/usr/bin/resolveip
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option
以前的问题还没有解决,又来新问题啦。。。
Google搜索下,搜到了以下链接的文章:
http://blog.chinaunix.net/space.php?uid=259788&do=blog&id=2139245
试了各种办法,都没法解决,包括修改hosts文件,最后只能强制执行了。
(后来我发现,其实只要将/etc/hostname文件中的内容ip-10-146-22-118给修改为127.0.0.1就行了。)
sudo mysql_install_db --user=mysql --datadir=/var/lib/mysql --force
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h ip-10-146-22-118 password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/scripts/mysqlbug script!
还好,算是成功了。
等等!!
我这边已经是晚上11点了,系统上怎么显示的是下午一点呢!
难道东京亚马逊的AWS没有给俺设定好时区?
查看下:
date -R
Sat, 10 Dec 2011 13:50:00 +0000
果然,我这边是东9区。它竟然给我弄个0区。
先搜索如何修改:
http://www.xgdown.com/article/53/142110_1.htm
再修改之:
sudo cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
sudo ntpdate jp.pool.ntp.org
jp.pool.ntp.org是位于日本的公共NTP服务器,用来同步系统时间。
关于全球各地的NTP服务器,可以参考这里:
http://www.pool.ntp.org/zone/@
成功修改时间。
不好意思,跑题了。。。
接下来继续启动Mysql Server,靠,还有错!
sudo mysqld restart
111210 23:39:04 [Note] Plugin 'FEDERATED' is disabled.
111210 23:39:04 InnoDB: Initializing buffer pool, size = 8.0M
111210 23:39:04 InnoDB: Completed initialization of buffer pool
111210 23:39:04 InnoDB: Started; log sequence number 0 44233
mysqld: Too many arguments (first extra is 'restart').
Use --verbose --help to get a list of available options
111210 23:39:04 [ERROR] Aborting
111210 23:39:04 InnoDB: Starting shutdown...
111210 23:39:09 InnoDB: Shutdown completed; log sequence number 0 44233
111210 23:39:09 [Note] mysqld: Shutdown complete
继续Google搜索答案,尝试如下方法:
sudo chown mysql:mysql /var/lib/mysql/ -R
sudo chmod g+rw /var/lib/mysql/ -R
sudo /usr/sbin/mysqld --skip-grant &
还是出错:
sudo mysqld
111211 0:40:54 [Note] Plugin 'FEDERATED' is disabled.
111211 0:40:54 InnoDB: Initializing buffer pool, size = 8.0M
111211 0:40:54 InnoDB: Completed initialization of buffer pool
111211 0:40:54 InnoDB: Started; log sequence number 0 44233
111211 0:40:54 [ERROR] Can't start server : Bind on unix socket: No such file or directory
111211 0:40:54 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?
111211 0:40:54 [ERROR] Aborting
111211 0:40:54 InnoDB: Starting shutdown...
111211 0:40:59 InnoDB: Shutdown completed; log sequence number 0 44233
111211 0:40:59 [Note] mysqld: Shutdown complete
没有写目录的权限。就给它写的权限:
sudo chmod 777 /var/run/mysqld/
再次运行 sudo mysqld &, 成功启动。
但是登陆的时候又出问题!
E
RROR 1045 (28000): Access denied for user ''@'localhost' (using password: NO)
解决办法:
1,先停止mysqld服务, 注意,u,p后没有空格
sudo mysqladmin -uroot -ppassword shutdown
2,通过以下方式启动Mysql Server
sudo mysqld --skip-grant &
3,输入mysql命令,进入,然后执行以下语句。
mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> \q
4,再次启动Mysql Server。
sudo mysqld &
5,使用以下命令登陆Mysql数据库:
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.58-1ubuntu1 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
终于成功。
真折腾人啊,每次重新弄个环境,就要花费好长时间折腾这些玩意儿。
下面的内容挺有用的,分享下链接:
http://www.cnblogs.com/wuhou/archive/2008/09/28/1301071.html