Q. How do I install MySQL database server under Redhat Enterprise Linux 5?
A. You have two choices:
a) Install MySQL package using RHN
b) Install MySQL rpm from CD/DVD
Red hat Enterprise Install Mysql Database server
The best way to install mysql package is to use RHN (Red Hat Network):
Redhat Enterprise Linux - RHEL 5 MySQL installation
Type the following command as root user:
# yum install mysql-server mysql
Note above yum command works with Fedora core and Cent OS Linux.
Redhat Enterprise Linux - RHEL 4/3 MySQL installation
Type the following command as root user:
# up2date mysql-server mysql
Start MySQL Service
To start mysql server type the following command:
# chkconfig mysqld on
# /etc/init.d/mysqld start
Setup mysql root password
Type the following command to setup a password for root user:
# mysqladmin -u root password NEWPASSWORD
Test mysql connectivity
Type the following command to connect to MySQL server:
$ mysql -u root -p
Fix: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
if you are new to installing mysql server you might probably face this error quite often if you type mysql in the shell prompt.
> mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
To fix:
First start the mysql daemon, then type mysql
> /etc/init.d/mysqld start
> mysql
Bingo! It worked for me!
To update mysql root password
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD(‘new-password’) WHERE user=’root’;
mysql> FLUSH PRIVILEGES;
To add a new user to mysql
1. First login as root then create a database ‘demo’
> mysql -u root -p
Enter password:
mysql> create database demo;
After that create a new user named ‘guest’ with password ‘guest’ with all previleges assigned to demo database;
mysql> GRANT ALL PRIVILEGES ON mytest.* TO ‘guest’@'localhost’ IDENTIFIED BY ‘guest’ WITH GRANT OPTION;
Then exit mysql and connect through username guest;
That should work!
Correct syntax to start / stop / restart with sudo:
sudo /etc/init.d/mysqld start
sudo /etc/init.d/mysqld status
sudo /etc/init.d/mysqld restart
sudo /etc/init.d/mysqld stop
OR
sudo /sbin/service mysqld start
What is the output of the following command?
netstat -tulnp | grep mysql
启动mysql时报错:
Starting mysqld daemon with databases from /var/lib/mysql
STOPPING server from pid file /var/run/mysqld/mysqld.pid
071112 00:22:06 mysqld ended
查看日志:
#less /var/log/mysqld.log
其中有一段如下:
071112 0:22:06 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)
071112 0:22:06 [ERROR] Can't start server: can't create PID file: No such file or directory
071112 00:22:06 mysqld ended
#cd /var/run/
#ls
mysqld目录不存在,创建它:
#mkdir /var/run/mysqld
#cd /var/run/mysqld
创建文件mysqld.pid:
#touch mysqld.pid
#cd..
#chown -R mysql mysqld .
#cd /usr/local/mysql/
#bin/mysqld_safe --user=mysql &
nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /var/lib/mysql
能正常启动
#bin/mysqladmin -u root password root
又出错
[root@localhost mysql]# bin/mysqladmin -u root password root
bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
[root@localhost mysql]# bin/mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
分析:是/tmp/mysql.sock 不存在
# cd /var/lib/mysql/
由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,创建符号连接:
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
# bin/mysql -u root
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.0.45 MySQL Community Server (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
我将s9当众原来的mysql4.0删除后,重新装了个mysql5.0,启动过程中报一下错误,启动失败,查了一下群里面的老帖子也没有个具体的明确说明,还请那位高手说明一下怎么解决。谢谢
error 日志当中的记录:
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
从发了帖子,只有人看,没有人回复,看到这种情况只能自己解决问题了,自己动手丰衣足食吗, 嗯。。。 你还别说,还真让我解决了问题,人啊,都是逼出来的,....没有办法,这个问题对于高手可能是很简单的问题 ,但是对我第一次摸mysql,确实怎么也弄不懂的问题。
好了闲话不多说 说一下我解决的过程:
按照mysql的安装步骤:
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root /usr/local/mysql
shell> chown -R mysql /usr/local/mysql/var
shell> chgrp -R mysql /usr/local/mysql
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
这样标准进行下来是没有问题的,但在最后一步启动mysql的时候我希望将数据库的数据文件放在另外一个目录下面,启动命令修改为:
shell>/usr/local/mysql/bin/mysqld_safe --user=mysql --log-error=/u01/mysql/mysql_error/error --datadir=/u01/mysql/data
这个时候就出现问题了,
因为在进行初始化数据库权限表的那一步的时候默认创建的权限表在默认目录/usr/local/mysql/var下面,这就造成了,上面的错误无法找到
权限表:Can't open and lock privilege tables: Table 'mysql.host' doesn't
exist
解决办法 在运行初始化权限表的时候使用增加参数--datadir ,命令格式为:
shell> scripts/mysql_install_db --user=mysql --datadir=/u01/mysql/data
这样问题就解决了。
这样问题同样也会出现 你将自己的数据库的数据文件修改为别的目录的时候,因为你没有在相应的目录下创建数据库权限表,解决办法就是你重新运行mysql_install_db 文件,重新生成数据库权限表,但是相应的你也要重新建里用户,以及设置权限; 第二个办法应该将老的权限表的文件拷贝倒相应数据库表对应的目录先即可,但是第二个办法我没有用过只是根据自己的想象猜的。如果有高手请给确认一下是否正确
|