您的位置:首页 > 运维架构 > Linux

centos 安装mysql,通用二进制包安装

2015-08-09 16:34 531 查看

安装平台:centos6.5 32位,64位请下载64位版本的数据库

mysql下载地址:http://pan.baidu.com/s/1o6HxW50,mysql-5.1.49,单击下载。

一般linux系统默认都安装有mysql,所以在进行安装前,需要检查系统是否已经安装,



运行命令:rpm -qa | grep -i mysql,如果安装了mysql,就会有提示,有的系统没有安装mysql数据库,但可能

安装了mysql的库文件,



类似于mysql-libc-xxx这个也要卸载。

卸载命令: rpm -e --nodeps mysql-xxx

卸载完后,运行rpm -qa | grep mysql 查看是否卸载完全。



接下正式开始安装:



1. 将mysql的tar文件mysql-5.1.49-linux-x86_64-glibc23.tar.gz拷贝到centos的usr/local目录下。



进入/usr/local目录下,运行命令tar -zxvf mysql-5.1.49-linux-x86_64-glibc23.tar.gz解压该文件。



解压以后的文件夹名字会很长,这里改一下名字,改为mysql-5.1.49:

mv mysql-5.1.49-linux-x86_64-glibc23.tar.gz mysql-5.1.49



2.添加mysql的用户和组,如果已经存在可以跳过这一步

groupadd -r -g 306 mysql #-r表示是伪用户,只是用来运行mysql程序,不能登录系统

useradd -g 306 -r -u 306 mysql



3.将安装文件的所属设置为mysql,这里将数据文件目录设置到$MYSQL_HOME/data下



[root@mysql1 mysql-5.1.49]# chown -R mysql.mysql /usr/local/mysql-5.1.49/*



[root@mysql1 mysql-5.1.49]# chown -R mysql.mysql /usr/local/mysql-5.1.49/data



4.配置mysql的配置文件,将suppotr-files下的my-mediu.cnf拷到/etc下并重命名为 my.cnf

cp support-files/my-medium.cnf /etc/my.cnf

修改my.cnf文件,加入配置信息

gedit /etc/profile //在这里加入mysql的环境变量

[mysqld]



basedir = /usr/local/mysql-5.1.49



datadir = /usr/local/mysql-5.1.49/data



default-character-set=utf8 //配置字符编码



port = 3306



sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES



然后保存,退出。



5.初始化mysql



进入mysql安装目录,我这里是usr/local/mysql-5.1.49,运行一下命令。



[root@mysql mysql-5.1.49]#scripts/mysql_install_db --user=mysql --datadir=/mydata/data/



6.将support-files目录中将mysql.server复制到/etc/init.d中的mysqld中,创建初始化进程,并且加到服务中

[root@mysql1 mysql-5.1.49]# cp support-files/mysql.server /etc/init.d/mysqld

[root@mysql1 mysql-5.1.49]# chmod +x /etc/init.d/mysqld //为目录添加执行权限

[root@mysql1 mysql-5.1.49]# ls -l /etc/init.d/mysqld //查看权限

[root@mysql1 mysql-5.1.49]# chkconfig --add mysqld //将mysqld设为开机启动,若不想开机启动,则可 忽略此步



[root@mysql1 mysql-5.1.49]# chkconfig --list |grep mysqld //查看是否将mysql加入到了开机启动,运行以后,会有以下输出



mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

其中只要2-5是on,就表示设置成功。



7.配置环境变量



[root@mysql1 mysql-5.1.49]# vi /etc/profile



在文件的最下面加入mysql的环境变量信息,加入以下两句:



export MYSQL_HOME=/usr/local/mysql-5.1.49

export PATH=$PATH:$MYSQL_HOME/bin



8.启动进入mysql



[root@mysql1 mysql-5.1.49]#service mysqld start



修改mysql的密码,mysql默认用户名为root,密码为空,这里修改一下密码为root,你可以修改为你想要的。

[root@mysql1 mysql-5.1.49]# mysqladmin -u root password root



最后一步,登录mysql



[root@mysql1 mysql-5.1.49]#mysql -u root -p



Enterpassword:root //这里输入刚设置的密码



如果成功了,就会进入mysql,会有以下界面:



Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.6.20-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

到此,mysql的安装就结束了。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: