1、检查是否已安装,grep的-i选项表示匹配时忽略大小写

  rpm -qa|grep -i mysql

  *可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸:载时使用了--nodeps选项,忽略了依赖关系

  rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

2、 添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组。

  groupadd mysql

  useradd -r -g mysql mysql

  *useradd -r参数表示mysql用户是系统用户,不可用于登录系统。

3、  将二进制文件解压到指定的安装目录,我们这里指定为/usr/local

  cd/usr/local/

  tar zxvf /path/to/mysql-cluster-gpl-7.3.11-linux-glibc2.5-x86_64.tar.gz

  *加压后在/usr/local/生成了解压后的文件夹mysql-5.5.29-linux2.6-x86_64,这名字太长,我们为它建立一个符号链接mysql,方便输入。

  ln -s mysql-cluster-gpl-7.3.11-linux-glibc2.5-x86_64 mysql

  /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

  

e.     进入mysql文件夹,也就是mysql所在的目录,并更改所属的组和用户。

[root@localhost local]#cd mysql

[root@localhost mysql]#chown -R mysql .

[root@localhost mysql]#chgrp -R mysql .

f.       执行mysql_install_db脚本,对mysql中的data目录进行初始化并创建一些系统表格。注意mysql服务进程mysqld运行时会访问data目录,所以必须由启动mysqld进程的用户(就是我们之前设置的mysql用户)执行这个脚本,或者用root执行,但是加上参数--user=mysql。

[root@localhost mysql]scripts/mysql_install_db --user=mysql

*如果mysql的安装目录(解压目录)不是/usr/local/mysql,那么还必须指定目录参数,如

[root@localhost mysql]scripts/mysql_install_db --user=mysql \

--basedir=/opt/mysql/mysql \

--datadir=/opt/mysql/mysql/data

*将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data/目录下所有文件的所有者。

[root@localhost mysql]chown -R root .

[root@localhost mysql]chown -R mysql data

g.     复制配置文件

[root@localhost mysql] cp support-files/my-medium.cnf /etc/my.cnf

h.  将mysqld服务加入开机自启动项。

*首先需要将scripts/mysql.server服务脚本复制到/etc/init.d/,并重命名为mysqld。

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

*通过chkconfig命令将mysqld服务加入到自启动服务项中。

[root@localhost mysql]#chkconfig --add mysqld

*注意服务名称mysqld就是我们将mysql.server复制到/etc/init.d/时重命名的名称。

*查看是否添加成功

[root@localhost mysql]#chkconfig --list mysqld

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

i.  重启系统,mysqld就会自动启动了。

*检查是否启动

[root@localhost mysql]#netstat -anp|grep mysqld

tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      2365/mysqld

unix  2     [ ACC ]     STREAM     LISTENING     14396 2365/mysqld        /tmp/mysql.sock

*如果不想重新启动,那可以直接手动启动。

[root@localhost mysql]#service mysqld start

Starting MySQL.. SUCCESS!

j.       运行客户端程序mysql,在mysql/bin目录中,测试能否连接到mysqld。

[root@localhost mysql]#/usr/local/mysql/bin/mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 2

Server version:5.5.29-log MySQL Community Server (GPL)

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

Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners.

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

mysql> quit

Bye

*此时会出现mysql>命令提示符,可以输入sql语句,输入quit或exit退出。为了避免每次都输入mysql的全路径/usr/local/mysql/bin/mysql,可将其加入环境变量中,在/etc/profile最后加入两行命令:

MYSQL_HOME=/usr/local/mysql

export PATH=$PATH:$MYSQL_HOME/bin

这样就可以在shell中直接输入mysql命令来启动客户端程序了

[root@localhost mysql]#mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 3

Server version:5.5.29-log MySQL Community Server (GPL)

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

Oracle is a registeredtrademark of Oracle Corporation and/or its

affiliates. Other namesmay be trademarks of their respective

owners.

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

mysql>

linux 安装mysql服务的更多相关文章

  1. linux安装mysql服务分两种安装方法:

    linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有十多M,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点是安装速度 ...

  2. CentOs Linux 安装MySql服务失败 安装需要依靠包error:Failed dependencies

    [root@sh158-xen data]#rpm -ivh MySQL-server-5.5.24-1.linux2.6.x86_64.rpm error: Failed dependencies: ...

  3. 在RedHat5.4 LINUX 安装mySQL数据库

    linux下mysql 最新版安装图解教程 1. 查看当前安装的linux版本 通过上图中的数据可以看出安装的版本为RedHat5.4,所以我们需要下载RedHat5.4对应的mysql安装包

  4. CentOS7 安装 Mysql 服务

    我希望所有的软件包都用 rpm.yum 安装,这样卸载.升级.管理方便,可是自带的 yum 仓库里面没有 mysql-server 或者不是最新的,我需要安装MySQL官方的 yum 仓库, http ...

  5. linux安装mysql后root无法登录 sql 无法登录

    linux安装mysql后root无法登录 问题:[root@localhost mysql]# mysql -u root -pEnter password: ERROR 1045 (28000): ...

  6. 在Mac OS环境下安装MySQL服务

    在Mac OS环境下安装MySQL服务 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我之前介绍过window环境下安装mysql服务,以及在Linux环境下安装mysql服务,今 ...

  7. linux安装mysql~~~mysql5.6.12

    Linux安装mysql服务器 准备: MySQL-client-5.6.12-1.rhel5.i386.rpm MySQL-server-5.6.12-1.rhel5.i386.rpm 首先检查环境 ...

  8. linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题]

    linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题] 一.查看mysql是否已经安装 使用“whereis mysql”命令来查看mysql安装路径: [root@h ...

  9. Linux 安装Mysql(图文教程)

    原文:Linux 安装Mysql(图文教程) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net ...

随机推荐

  1. hdu 3715(二分+2-sat)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3715 思路:二分深度,2-sat判断可行性,根据矛盾关系建图:设a=0,a'=1,b=0,b'=1;如 ...

  2. NGINX快速部署

    NGINX快速部署 #!/bin/bash ############################################################################## ...

  3. Android开发:fragment将事件传递回activity

    fragment触发事件后传递会给activity,可以通过在fragment中定义一个接口,让activity实现这个接口. 具体代码如下 public class AAFragment exten ...

  4. mysql中对应oracle中的to_char()和to_number()函数

    TO_CHAR(): CAST(123   AS   CHAR(3)) TO_NUMBER(): cast( '123 '   as   SIGNED   INTEGER)

  5. GBK和UTF-8文字编码的区别

    UTF-8是一种国际化标准的文字编码,我们已知Windows系统程序已经将最初的UTF-8转向Unicode,而GBK的存在是为了中国国情而创造的,不过GBK也将伴随着中文字符的一直流传下去. GBK ...

  6. cxGrid时间格式与导出Excel

    引用cxFormats单元: ShortDateFormat := 'dd/mm/yyyy'; DateSeparator := '/'; cxFormatController.UseDelphiDa ...

  7. Apache JServ Protocol (AJP)

    The Apache JServ Protocol (AJP) is a binary protocol that can proxy inbound requests from a web serv ...

  8. python 中 for使用小技巧

    testDict = {i: i * i for i in xrange(10)} testSet = {i * 2 for i in xrange(10)} print(testSet) print ...

  9. 使用Kotlin开发Android应用(IV):自定义视图和Android扩展

    在读完扩展函数和默认值这篇文章之后,那么接下来要介绍什么呢?在本系列第一篇文章中我们说过,Kotlin使得Android开发更加简单,本文我们将进一步作介绍. 自定义视图 你应该还记得,在说到Kotl ...

  10. [转载]威力导演14旗舰破解版(中文简体)|取消30天限制CyberLink&nb

               2015月9月15日(当地时间),CyberLink讯连科技发布新一代视频编辑软件 — PowerDirector威力导演14,融合了上个版本发布以来的多次更新升级,威力导演依旧 ...