一、安装方法
安装MySQL主要有两种方法:一种是通过源代码进行编译安装,适合高级用户自己定制MySQL的特性;另一种比较简单的是使用已经编译过的二进制文件进行安装。二进制文件安装又分为不针对特定平台的通用安装方法,即.tar.gz压缩文件;另一种是使用RPM或其他包进行安装,这种方式会自动完成系统的相关配置。本次记录使用.tar.gz文件安装过程。
二、下载文件
mysql-5.5.45-linux2.6-x86_64.tar.gz(附件中有)
http://dev.mysql.com/downloads/mysql/5.5.html
三、检查是否已经安装,grep -i选项表示匹配时忽略大小写
[[email protected] /]# rpm -qa|grep -i mysql
perl-DBD-MySQL-4.013-3.el6.x86_64
mysql-libs-5.1.61-1.el6_2.1.x86_64
mysql-5.1.61-1.el6_2.1.x86_64
可见已经安装了库文件,应该先卸载,避免出现覆盖错误。卸载时使用--nodeps选项,忽略依赖关系:
[[email protected] /]# rpm -e mysql-5.1.61-1.el6_2.1.x86_64 --nodeps
[[email protected] /]# rpm -e perl-DBD-MySQL-4.013-3.el6.x86_64 --nodeps
[[email protected] /]# rpm -e mysql-libs-5.1.61-1.el6_2.1.x86_64 --nodeps
四、添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组
[[email protected] /]# groupadd mysql
[[email protected] /]# useradd -r -g mysql mysql (-r参数表示mysql用户是系统用户,不可用于登录系统)
五、安装
1.将二进制文件解压至指定目录,比如/usr/local
[[email protected] /]# cd /usr/local
[[email protected] /usr/local]# tar zxf mysql-5.5.45-linux2.6-x86_64.tar.gz
文件夹名字太长,做一个符号链接[[email protected] /usr/local]# ln -s mysql-5.5.45-linux2.6-x86_64 mysql
2.查看下/usr/local/mysql/下的目录结构
Directory |
Contents of Directory |
bin |
Client programs and the mysqld server |
data |
Log files, databases |
docs |
Manual in Info format |
man |
Unix manual pages |
include |
Include (header) files |
lib |
Libraries |
scripts |
mysql_install_db |
share |
Miscellaneous support files, including error messages, sample configuration files, SQL for database installation |
sql-bench |
Benchmarks |
3.改变所属的组和用户
[[email protected] /usr/local/mysql]# chown -R mysql .
[[email protected] /usr/local/mysql]# chgrp -R mysql .
4.执行mysql_install_db脚本,对mysql中的data目录进行初始化并创建一些系统表格。mysql服务的进程mysqld运行时要访问data目录,所以必须由mysqld的用户(前面设置的mysql)执行这个脚本,或者由root执行并加上参数--user=mysql:
[[email protected] /usr/local/mysql]# scripts/mysql_install_db --user=mysql
执行情况:
Installing MySQL system tables...
150809 11:20:06 [Note] ./bin/mysqld (mysqld 5.5.45) starting as process 28004 ...
OK
Filling help tables...
150809 11:20:06 [Note] ./bin/mysqld (mysqld 5.5.45) starting as process 28011 ...
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:
./bin/mysqladmin -u root password ‘new-password‘
./bin/mysqladmin -u root -h DevTJ-todo-15070919100 password ‘new-password‘
Alternatively you can run:
./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 . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
PS:如果mysql的安装目录(解压目录)不是/usr/local/mysql,那么还必须指定目录参数,如
[[email protected] /usr/local/mysql]# scripts/mysql_install_db --user=mysql \
--basedir=/opt/mysql/mysql \
--datadir=/opt/mysql/mysql/data
5.将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data目录下所有文件的所有者。
[[email protected] /usr/local/mysql]# chown -R root .
[[email protected] /usr/local/mysql]# chown -R mysql data .
6.将配置文件复制到/etc/my.cnf
[[email protected] /usr/local/mysql]# cp support-files/my-medium.cnf /etc/my.cnf
7.将mysqld服务加入开机启动项。
a.将scripts/mysql.server服务脚本复制到/etc/init.d,并重命名为mysqld
[[email protected] /usr/local/mysql]# cp support-files/mysql.server /etc/init.d/mysqld
b.通过chkconfig命令将mysqld服务加入到开机启动服务
[[email protected] /usr/local/mysql]# chkconfig --add mysqld
查看添加是否成功:
[[email protected] /usr/local/mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
六、修改配置,启动
1.修改配置
[[email protected] /usr/local/mysql]# vim /etc/my.cnf
初始配置只有:
可根据个人需要进行配置。
2.启动。
a.重启系统mysqld就会自动启动,或者直接手动启动msql。
[[email protected] /usr/local/mysql]# service mysqld start
Starting MySQL... SUCCESS!
b.添加用户,重启mysql。
补充,安装mysql client
[[email protected]]#rpm -ivh MySQL-client-5.5.28-1.linux2.6.x86_64.rpm