Linux下MySQL server和client安装

一、安装方法

安装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

时间: 2024-08-27 10:16:10

Linux下MySQL server和client安装的相关文章

数据库学习之--Linux下Mysql源码包安装

数据库学习之--Linux下Mysql源码包安装 系统环境: 操作系统:RedHat EL6 DB Soft:  Mysql 5.6.4-m7     Mysql 在linux下的安装方式有两种版本,一种为Binary(二进制),另外一种为Source(源码包),本文为Source Install方式. 1.安装前的准备 解压安装包 [[email protected] ~]$ ls mysql-5.6.4-m7  mysql-5.6.4-m7.tar.gz  mysql-5.6.4-m7.ta

Linux下MySQL的几种安装方式

闲来有空,整理下Linux下Mysql的几种安装方式,分别使用yum/rpm.常规方式编译安装.cmake方式编译安装以及使用二进制方式免编译安装MySQL Linux系统环境: CentOS release 6.5 (Final) x86_64 MySQL版本:5.5.45 安装前关闭了iptables.selinux为disabled 预安装以下包: yum groupinstall "debugging Tools" "Dial-up Networking Suppor

Linux下mysql的部署和安装-RPM方式

RPM方式安装MySQL5.6 a. 检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称) [[email protected] ~]# rpm -qa | grep -i mysql mysql-libs-5.1.66-2.el6_3.x86_64 [[email protected] ~]# yum -y remove mysql-libs* b. 下载Linux对应的RPM包,如:CentOS6.4_64对应的RPM包,如下: [[email protected

Linux下MySQL的下载、安装及启动

测试环境 主机系统:Win7 64位 虚拟机:VMware® Workstation 11.1.0 虚拟机系统:CentOS 6.5 64位   Kernel 2.6.32-431.e16.x86_64 MySQL: 5.6.24 1. Mysql的下载 a. 官网  http://dev.mysql.com/downloads/mysql/5.6.html#downloads b. 下载跟OS对应的mysql版本 [[email protected] ~]# uname –a         

linux下mysql源码包安装

1.下载下载地址: http://dev.mysql.com/downloads/mysql/5.6.html#downloads yeke 也可以直接复制下载命令 wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz 2.安装依赖性文件 yum -y install cmake bison git ncurses-devel gcc gcc-c++ 3.创建用户组 groupadd mysql useradd

Linux下Mysql 5.6+的安装

依赖: gcc.gcc-c++ GUN编译器套件 ncurses-devel ncurses 提供字符终端处理库 kernel-devel 操作系统内核 bison 属于 GNU 项目的一个语法分析器生成器 cmake CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程) 解决依赖方法 1.)使用yum [[email protected]/] yum install gccgcc-c++ kernel-devel ncurses-devel bison c

Linux下MySQL安装和配置

--Linux下MySQL安装和配置 ---------------------------2014/05/18 Linux下MySQL的配置和安装 本文的安装采用 rpm 包安装 1.首先在官网下载 http://dev.mysql.com/downloads/mysql/ MySQL-client-5.6.17-1.el6.i686.rpm MySQL-server-5.6.17-1.el6.i686.rpm 2.由于RedHat中自带了mysql-libs-5.1 会和 MySQL-ser

Liunx 下MYSQL 5.7 二进制安装

Linux 下 MySQL 5.7 二进制安装 数据库服务器操作系统配置可参看<Linux下MYSQL 5.6 源码安装>https://www.cnblogs.com/doctormo/p/12019550.html 这里采用的是 mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz, 可从MySQL官网 https://dev.mysql.com/downloads/mysql 下载5.7 版本. 1.1 安装必要的依赖包 # yum -y install

linux下MySQL 5.6源码安装

linux下MySQL 5.6源码安装 1.下载:当前mysql版本到了5.6.20 http://dev.mysql.com/downloads/mysql 选择Source Code 2.必要软件包 yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake 3.编译安装 添加用户 groupad