linux 安装mysql服务

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所在的目录,并更改所属的组和用户。

[[email protected] local]#cd mysql

[[email protected] mysql]#chown -R mysql .

[[email protected] mysql]#chgrp -R mysql .

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

[[email protected] mysql]scripts/mysql_install_db --user=mysql

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

[[email protected] mysql]scripts/mysql_install_db --user=mysql \

--basedir=/opt/mysql/mysql \

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

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

[[email protected] mysql]chown -R root .

[[email protected] mysql]chown -R mysql data

g.     复制配置文件

[[email protected] mysql] cp support-files/my-medium.cnf /etc/my.cnf

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

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

[[email protected]]  cp support-files/mysql.server /etc/init.d/mysqld

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

[[email protected] mysql]#chkconfig --add mysqld

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

*查看是否添加成功

[[email protected] mysql]#chkconfig --list mysqld

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

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

*检查是否启动

[[email protected] 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

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

[[email protected] mysql]#service mysqld start

Starting MySQL.. SUCCESS!

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

[[email protected] 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命令来启动客户端程序了

[[email protected] 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>

时间: 2024-08-07 08:26:41

linux 安装mysql服务的相关文章

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

[[email protected] data]#rpm -ivh MySQL-server-5.5.24-1.linux2.6.x86_64.rpm error: Failed dependencies: MySQL conflicts with mysql-5.0.77-4.el5_4.2.x86_64纠结了半天,终于找到了解决方法:(感谢提供相关文章的博友) 在安装包后面加两个参数,如 [[email protected] data]#rpm -ivh MySQL-server-5.5.2

Linux 安装 MySQL 以及 一些常见问题解决方案

一.下载MySql浏览器打开 http://www.mysql.com/downloads/mysql/#downloads 下载 我下载的版本是Red Hat 5 版本的 http://www.mysql.com/downloads/mirror.php?id=407552 上传至服务器,或在服务器上直接 wget 下载方式下载.(我在服务器上存放在目录/opt/tools 下) 二.解压tar文件执行命令:tar -xvf MySQL-5.5.23-1.rhel5.x86_64.tar 三.

linux安装MySQL记录

目录 linux安装MySQL记录 1. 在根目录下创建文件夹/software和数据库数据文件/data/mysql 2. 从官网下载相应的MySQL版本 3. 解压并移动到/software目录下 4. 创建mysql用户组和mysql用户 5. 关联myql用户到mysql用户组中 6. 更改文件夹的权限 7. 安装libaio依赖包 8. 初始化mysql命令 9. 修改Mysql配置文件 10. 启动MySQL服务 11. 登录mysql 12. 修改mysql的登录密码 13. My

Linux安装及服务控制

一.  版本 Red Hat 企业版   Red Hat Enterprise Linux (简称RHEL) http://www.redhat.com Fedora社区版 由Red Hat资助的社区维护,定位于个人桌面用户 http://fedoraproject.org CentOS社区版 Community Enterprise Operating System(社区企业操作系统) http://www.centos.org 二.  安装步骤 插入RHEL6安装光盘,引导安装程序 设置主机

Linux安装mysql

——@梁WP 摘要:Linux安装mysql. 一.下载mysql 1.在百度搜索mysql,看到其中有一条结果是带有MySQL Downloads字样的,点击进入mysql的官网. 2.进入mysql官网之后,在下面能见到MySQL Community Edition (GPL),点击下面的链接,就会进入下载列表. 3.在下载列表找到MySQL Community Server,点击下面的链接,会进入产品选择页面. 4.选择对应的操作系统,然后选择合适的版本(.gz格式),截图选了Linux 

Linux安装weblogic服务

Linux安装weblogic服务 一.环境准备: Linux系统 jdk-7u75-linux-x64.tar.gz(http://pan.baidu.com/s/1kTh5Vx1) wls1212_dev.zip(http://pan.baidu.com/s/1nttDkq1) 二.安装步骤: 1.首先创建weblogic用户.用户组并设置主目录 [[email protected] ~]# useradd -d /weblogic weblogic [[email protected] ~

压缩包安装MySQL服务

上次忘了压缩包怎么安装mysql服务,希望以后不要再忘了 在windows上安装MySQL有两种方式,使用MySQLInstaller,使用压缩文件 需要注意的几点1,解压目录就是安装目录.2,建配置文件(Option File),解压后根目录里有my-default.ini.官网描述MySQL Server在Windows 上启动时会在C:\.安装目录等处寻找配置文件,配置文件可以命名为my.ini(优先选择).my.conf( 如果c盘不是启动盘,不能使用my.conf).3,MySQL 5

linux安装mysql、tomcat和jdk1.7、Android Studio

linux安装mysql.tomcat和jdk. 一.安装mysql $ sudo apt-get install mysql-server 安装mysql 二.安装JDK 下载jdk 到达/usr/local $ sudo mkdir java 建立一个java文件夹 (注:sudo 请求root权限 ) $ sudo mv jdk1.7.0_67 /usr/local/java 将解压的文件移到刚刚建好的文件夹 $ sudo vim /etc/profile 可能vim编辑器没有安装 因此执

一键自动化安装mysql服务端

声明 作者:昨夜星辰 博客:http://yestreenstars.blog.51cto.com/ 本文由本人创作,如需转载,请注明出处,谢谢合作! 目的 一键自动化安装mysql服务端. 环境 OS: CentOS 6.2 32 mysql: 5.6.20 配置 #!/bin/bash # Script Name: One-key Automatic Install MySQL server # Author: yestreenstars # Create Time: 2014-08-18