- 准备MySQL-5.5.24-1.rhel5.x86_64.tar
解压MySql安装包
[root@bakdbserver mysql]# tar -xf MySQL-5.5.24-1.rhel5.x86_64.tar
[root@bakdbserver mysql]# ll
总计 373920
-rw-r–r– 1 root root 191242240 2012-05-28 MySQL-5.5.24-1.rhel5.x86_64.tar
-rw-r–r– 1 7161 wheel 18204697 2012-04-19 MySQL-client-5.5.24-1.rhel5.x86_64.rpm
-rw-r–r– 1 7161 wheel 3869191 2012-04-19 MySQL-devel-5.5.24-1.rhel5.x86_64.rpm
-rw-r–r– 1 7161 wheel 69218533 2012-04-19 MySQL-embedded-5.5.24-1.rhel5.x86_64.rpm
-rw-r–r– 1 7161 wheel 55049591 2012-04-19 MySQL-server-5.5.24-1.rhel5.x86_64.rpm
-rw-r–r– 1 7161 wheel 2083987 2012-04-19 MySQL-shared-5.5.24-1.rhel5.x86_64.rpm
-rw-r–r– 1 7161 wheel 42805943 2012-04-19 MySQL-test-5.5.24-1.rhel5.x86_64.rpm创建MySql系统管理用户
[root@bakdbserver ~]# groupadd mysql
[root@bakdbserver ~]# useradd -g mysql mysql
[root@bakdbserver mysql]# id mysql
uid=502(mysql) gid=54325(mysql) groups=54325(mysql)安装 MySql rpm包
[root@bakdbserver mysql]# rpm -ivh “*.rpm”
Preparing… ########################################### [100%]
1:MySQL-client ########################################### [ 17%]
2:MySQL-devel ########################################### [ 33%]
3:MySQL-embedded ########################################### [ 50%]
4:MySQL-server ########################################### [ 67%]
5:MySQL-shared ########################################### [ 83%]
6:MySQL-test ########################################### [100%]
卸载顺序:
[root@bakdbserver ~]# rpm -e MySQL-server-5.5.24-1.rhel5
[root@bakdbserver ~]# rpm -e MySQL-embedded-5.5.24-1.rhel5
[root@bakdbserver ~]# rpm -e MySQL-shared-5.5.24-1.rhel5
[root@bakdbserver ~]# rpm -e MySQL-devel-5.5.24-1.rhel5
[root@bakdbserver ~]# rpm -e MySQL-test-5.5.24-1.rhel5
[root@bakdbserver ~]# rpm -e MySQL-client-5.5.24-1.rhel5
–此时MySql自动安装在mysql用户下
- 尝试在root用户启动mysql服务
[root@ods-mgr ods]# service mysql start
Starting MySQL.. SUCCESS!
先查看 /etc/rc.d/init.d/mysqld status 或者/etc/rc.d/init.d/mysql status
看看m y s q l 是否已经启动.
[root@bakdbserver ~]# ps -ef|grep mysql
root 17075 1 0 15:35 pts/1 00:00:00 /bin/sh /usr/bin/mysqld_safe –datadir=/var/lib/mysql –pid-file=/var/lib/mysql/bakdbserver.pid
mysql 17153 17075 0 15:35 pts/1 00:00:00 /usr/sbin/mysqld –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib64/mysql/plugin –user=mysql –log-error=/var/lib/mysql/bakdbserver.err –pid-file=/var/lib/mysql/bakdbserver.pid
root 17178 12211 0 15:35 pts/1 00:00:00 grep mysql
mysql安装软件在/usr/share/mysql目录下
Mysql数据库创建在/var/lib/mysql目录下
6. 修改安装目录权限
说明:
为了安全地管理MySQL,应使用系统的mysql专有用户进行MySQL的日常管理,为了使mysql用户有读写安装目录的权限,应修MySQL安装目录的权限。
[root@bakdbserver mysql]# cd /usr/share/mysql
[root@bakdbserver share]# chown -R mysql:mysql .
[root@bakdbserver mysql]# ll
总计 1324
-rwxr-xr-x 1 mysql mysql 1153 2012-04-19 binary-configure
drwxr-xr-x 2 mysql mysql 4096 08-23 11:39 charsets
-rwxr-xr-x 1 mysql mysql 4528 2012-04-19 config.huge.ini
…
–由于MySQL数据库目录已经是mysql用户权限,故不用修改
[root@bakdbserver mysql]# cd /var/lib/mysql
[root@bakdbserver mysql]# ll
总计 28752
drwx–x–x 2 mysql mysql 4096 08-23 09:17 mysql
drwx—— 2 mysql mysql 4096 08-23 09:17 performance_schema
-rw-r–r– 1 mysql mysql 616 08-23 11:39 RPM_UPGRADE_HISTORY
-rw-r–r– 1 mysql mysql 495 08-23 11:39 RPM_UPGRADE_MARKER-LAST
drwxr-xr-x 2 mysql mysql 4096 08-23 09:17 test
…
7. 启动MySQL服务器
处于安全方面的原因,应避免以Linux根用户身份运行服务器,应以mysql用户身份启动服务器。
[root@bakdbserver mysql]# ./mysql.server start –user=mysql
Starting MySQL..[确定]
或是
[root@bakdbserver mysql]# /usr/bin/mysqld_safe –user=mysql &
如果直接mysql 回车,报错,
mysql Access denied for user root@localhost错误解决方法总结
就先停了服务器,给root用户设置密码,重启就可以了
[root@ods-mgr mysql]# /etc/init.d/mysql stop
Shutting down MySQL.. SUCCESS!
之后
mysql -u root -p 进入数据库,输入密码
现在查看数据库会报如下的错;
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD(‘123456’);
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| test |
+——————–+
4 rows in set (0.00 sec)
大功告成