二、编译安装mysql-5.5.33

1、准备数据存放的文件系统:

新建一个逻辑卷(过程见链接),并将其挂载至/mydata/data目录, 做为mysql数据的存放目录。

http://858004880.blog.51cto.com/7265424/1759317

2、新建用户以安全方式运行进程:

1.删除系统原来的mysql用户家目录
[[email protected] ~]# userdel -rmysql

2.创建mysql系统用户组
[[email protected] ~]# groupadd -r mysql

3.添加mysql用户到mysql组并且指明路径
[[email protected] ~]# useradd -g mysql -r -s/sbin/nologin -M -d /mydata/data mysql
useradd[options] LOGIN
                            -g GID:指明用户所属基本组,可为组名,也可以GID;
                            -d/PATH/TO/HOME_DIR: 以指定的路径为家目录;
                            -s SHELL: 指明用户的默认shell程序,可用列表在/etc/shells文件中;
                            -r: 创建系统用户
                -M: 不自动创建用户的家目录
[[email protected] ~]# tail -2 /etc/passwd
mysql:x:498:499::/mydata/data:/sbin/nologin

4.修改数据文件属主:
[[email protected] ~]# chown -R mysql:mysql/mydata/data/
[[email protected] ~]# ll /mydata/
total 4
drwxr-xr-x3 mysql mysql 4096 Apr  1 16:21 data

3、安装并初始化mysql-5.6.29

3.1.安装所需要的  gccgcc-c++ ncurses-devel perl库:

[[email protected] tools]# yum -y install gcc gcc-c++ ncurses-devel perl

3.2.安装cmrk

[[email protected] tools]# wget https://cmake.org/files/v3.5/cmake-3.5.0.tar.gz
[[email protected] tools]# tar xf cmake-3.5.0.tar.gz
[[email protected] tools]# cd cmake-3.5.0
[[email protected] cmake-3.5.0]# ./bootstrap
[[email protected]]# gmake && gmake install

3.3.下载解压mysql5.5:

[[email protected] tools]# wget http://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.48.tar.gz
[[email protected]]# tar xf mysql-5.5.48.tar.gz.1

3.4.编译安装:

[[email protected] tool]# cdmysql-5.5.48 
[[email protected]]#
  cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock-DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
# make&& make install

3.5.修改mysql目录所有者和组

[[email protected] mysql-5.5.48]# cd /usr/local/mysql/
[[email protected]]# chown -R mysql:mysql .

3.6.初始化mysql数据库

# scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/mydata/data --user=mysql

3.7.为mysql提供主配置文件my.cnf:

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

3.8.修改my.cnf

修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:

thread_concurrency = 2

另外还需要添加如下行指定mysql数据文件的存放位置:

datadir = /mydata/data

[[email protected] mysql]# vim /etc/my.cnf
 
[mysqld]
# Try number of CPU‘s*2 for thread_concurrency
thread_concurrency = 2
datadir = /mydata/data
innodb_file_per_table = 1
skip_name_resolve = 1

3.9.为mysql提供sysv服务脚本:

[[email protected] mysql]# cpsupport-files/mysql.server /etc/rc.d/init.d/mysqld
[[email protected]]# chmod +x /etc/rc.d/init.d/mysqld

3.10.添加至服务列表:

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

3.11.输出mysql的man手册至man命令的查找路径:

为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:

编辑/etc/man.config,添加如下行即可:

MANPATH /usr/local/mysql/man

[[email protected] mysql]# vim /etc/man.config
 
#/var/cache/man/.../[locale/]catx/page.x.
# The keyword FHSwill cause this behaviour (and overrides FSSTND).
# Explicitly givencatdirs override.
#
# FSSTND
FHS
#
# This file is alsoread by man in order to find how to call nroff, less, etc.,
# and to determinethe correspondence between extensions and decompressors.
#
# MANBIN                /usr/local/bin/man
#
# Every automaticallygenerated MANPATH includes these fields
#
MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
MANPATH/usr/local/mysql/man

3.12.输出mysql的头文件至系统头文件路径/usr/include:

这可以通过简单的创建链接实现:

# ln -sv /usr/local/mysql/include  /usr/include/mysql

3.13.输出mysql的库文件给系统库查找路径:

# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf

3.14.让系统重新载入系统库:

# ldconfig

3.15.修改PATH环境变量:

编辑/etc/profile,在最后添加:

[[email protected] mysql]# vim /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH

保存退出;然后执行:

[[email protected] mysql]# source/etc/profile

环境变量添加成功

3.16. 启动mysql

[[email protected] mysql]# service mysqld start

3.17.输入mysql命令:

[[email protected] mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.48-log Source distribution
 
Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved.
 
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarks of theirrespective
owners.
 
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clearthe current input statement.
 
mysql>

mysql默认为空密码!

3.18. 修改MySQL用户root的密码

# 修改密码为test123:
mysql> SET PASSWORD FOR‘root‘@‘localhost‘ = PASSWORD(‘test123‘);
Query OK, 0 rows affected(0.00 sec)
 
mysql> SET PASSWORD FOR‘root‘@‘127.0.0.1‘ = PASSWORD(‘test123‘);
Query OK, 0 rows affected(0.00 sec)
 
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected(0.00 sec)
 
# 登录:
[[email protected] html]#mysql -uroot -p
Enter password: 
Welcome to the MySQLmonitor.  Commands end with ; or \g.
Your MySQLconnection id is 3
Server version:5.5.48-log Source distribution
 
Copyright (c) 2000,2016, Oracle and/or its affiliates. All rights reserved.
 
Oracle is aregistered trademark of Oracle Corporation and/or its
affiliates. Othernames may be trademarks of their respective
owners.
 
Type ‘help;‘ or ‘\h‘for help. Type ‘\c‘ to clear the current input statement.
 
mysql>

3.19. 优化mysql,清除无用的MySQL用户及库:

1.查看数据库:
mysql> show databases;   
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)
 
删除test库;
mysql> drop database test;
Query OK, 0 rows affected (0.03 sec)
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
 
删除mysql库中无用的用户:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|     | localhost |
| root | localhost |
|     | nginx.com |
| root | nginx.com |
+------+-----------+
6 rows in set (0.00 sec)
 
mysql> drop user [email protected]"::1";
Query OK, 0 rows affected (0.02 sec)
 
mysql> drop user ""@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql> drop user [email protected];
Query OK, 0 rows affected (0.00 sec)
 
mysql> drop user ""@nginx.com;
Query OK, 0 rows affected (0.00 sec)
删除以上4个无用的用户,只保留2个[email protected]和[email protected]用户。
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
 
注意:操作千万要细心,万一不小心删除了[email protected]这个用户,怎么办?
1.我们可以用[email protected]这个ip账号登录:
[[email protected] ~]# mysql -h 127.0.0.1 -uroot-p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.48-log Sourcedistribution
 
Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved.
 
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
 
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.
 
2.登录进来以后,再用grant命令来创建[email protected]用户,并且赋予root权限:
mysql> grant all privileges on *.* [email protected] identified by ‘test123‘;
Query OK, 0 rows affected (0.03 sec)
 
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit
Bye
 
3.我们再root账号在本地进行登录
[[email protected] ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.48-log Sourcedistribution
 
Copyright (c) 2000, 2016, Oracle and/or itsaffiliates. All rights reserved.
 
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
 
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.
我们在本地用root账号成功登录!
 
4.查看用户:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
[email protected]用户已经添加进来了!

mysql-5.5编译安装成功!

时间: 2024-08-05 11:15:16

二、编译安装mysql-5.5.33的相关文章

LAMP部署-- 二.编译安装Mysql

LAMP组件介绍 LAMP是指Linux.Apache,Mysql以及PHP的简称,目前许多生产环境的都是用的LAMP架构,在网络应用和开发环境方面,LAMP组合是非常棒的,它们的结合提供了强大的功能. Linux作为底层的操作系统,提供了灵活且安全的应用平台,为其他的组件稳定运行提供了保障: Apache作为web服务器,提供了功能强大.稳定与支撑能力突出的web平台: Mysql也是一款优秀的数据库软件: PHP是一种开发脚本语言,可以嵌入HTML中,适用于web开发: 准备工作 操作系统:

Linux CentOS6.5下编译安装MySQL 5.6.16【给力详细教程】

一.编译安装MySQL前的准备工作 安装编译源码所需的工具和库 [sql] view plaincopy yum install gcc gcc-c++ ncurses-devel perl 安装cmake,从http://www.cmake.org下载源码并编译安装 [sql] view plaincopy wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz tar -xzvf cmake-2.8.10.2.tar.gz cd 

CentOS 6.4下编译安装MySQL 5.6.16

一.卸载旧版本MySql 1.rpm卸载: 1> 检查安装包: rpm -qa | grep mysql 2> 普通删除: rpm -e mysql-5.6.16.rpm 3> 强力删除.如果使用上面命令删除时,提示有依赖的其他文件,则使用该命令可以对其进行强力删除. rpm -e --nodeps mysql-5.6.16.rpm 2.tar卸载: 1> 删除临时文件: make clean 2> 卸载 make uninstall 3> 删除解压文件 rm  -rf

编译安装Mysql与管理(十四)

[教程主题]:编译安装Mysql与管理 [课程录制]: 创E [主要内容] [1]什么是Mysql MyQL是一个开放源码的小型关系型数据库管理系统,开发者为瑞典MySQL AB公司.目前MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库. [2]安装Mysql 一.安装简介 用户名:mysql安装目录:/usr/local/mysql-5.5数据库目录:/

CentOS下使用cmake编译安装mysql

一.下载安装所必需的依赖包 1.因为高版本mysql都用cmake安装,所以下载cmake wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.gz tar zxvf cmake-3.0.1.tar.gz cd cmake-3.0.1 ./configure make && make install 2.下载其它包 wget http://ftp.gnu.org/gnu/bison/bison-3.0.2.tar.gz 安装同上 wge

CentOS 6.4下编译安装MySQL 5.6.14

CentOS 6.4下编译安装MySQL 5.6.14 概述: CentOS 6.4下通过yum安装的MySQL是5.1版的,比较老,所以就想通过源代码安装高版本的5.6.14. 正文: 一:卸载旧版本 使用下面的命令检查是否安装有MySQL Server rpm -qa | grep mysql 有的话通过下面的命令来卸载掉 rpm -e mysql //普通删除模式 rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对

CentOS 6.5下编译安装MySQL 5.6.20

概述:Centos 6.5下通过yum安装的MySQL是5.1版的,比较老,所以就想通过源代码安装高版本的5.6.20. 正文:一:卸载旧版本使用下面的命令检查是否安装有MySQL Server rpm -qa | grep mysql有的话通过下面的命令来卸载掉 rpm -e mysql  //普通删除模式rpm -e --nodeps mysql    // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除二:安装MySQL安装编译代码需要的包yum

LNMP搭建01 -- 编译安装MySQL 5.6.14 和 LNMP相关的区别

[编译安装MySQL 5.6.14] [http://www.cnblogs.com/xiongpq/p/3384681.html ]  [mysql-5.6.14.tar.gz 下载] http://pan.baidu.com/s/1jGIffFo   一:卸载旧版本 使用下面的命令检查是否安装有MySQL,若是初次安装直接跳过. rpm -qa | grep mysql 有的话通过下面的命令来卸载掉 其实很简单,直接删除编译后的安装目录,例如:/usr/local/mysql 即可. rpm

CentOS 6下编译安装MySQL 5.6

一:卸载旧版本 使用下面的命令检查是否安装有MySQL Server rpm -qa | grep mysql 有的话通过下面的命令来卸载掉 rpm -e mysql //普通删除模式 rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除 二:安装MySQL 安装编译代码需要的包 yum -y install make gcc-c++ cmake bison-devel ncurses-devel 下载MyS

Linux CentOS6.5下编译安装MySQL 5.6.29

一.编译安装MySQL前的准备工作 安装编译源码所需的工具和库 [[email protected] ~]# yum install gcc gcc-c++ ncurses-devel perl  安装cmake,从http://www.cmake.org下载源码并编译安装 [[email protected] ~]# wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz    [[email protected] ~]#tar -