Linux下安装mysql------源码安装

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介:

#创建mysql安装目录

1
mkdir  -p  /usr/local/mysql/

#创建数据存放目录

1
mkdir  -p  /data/mysql/

#创建用户和用户组与赋予数据存放目录权限

1
2
3
groupadd mysql                    #用户组可能已存在
useradd  -g mysql mysql              #用户可能已存在
chown  mysql.mysql -R  /data/mysql/          #给安装文件夹赋权限

#安装编译源码需要的包

1
[root@localhost mysql-5.6.25] # yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

#编译mysql

1
2
tar  zxvf mysql-5.6.25. tar .gz
cd  mysql-5.6.25
1
2
3
4
5
6
7
8
9
10
11
12
cmake . -DCMAKE_INSTALL_PREFIX= /usr/local/mysql  \
-DMYSQL_DATADIR= /data/mysql  \
-DMYSQL_UNIX_ADDR= /data/mysql/mysql .sock \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1

#编辑,时间比较长点,多等待下吧

1
make

#安装 mysql

1
make  install

#首先yum安装下perl:   yum -y install perl

#进入/usr/local/mysql/scripts 生成mysql用户数据库和表文件: ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
[root@localhost support-files] # cd /usr/local/mysql/scripts/
[root@localhost scripts] # yum -y install perl
 
[root@localhost scripts] # ll
total 36
-rwxr-xr-x. 1 root root 34558 Jan 13 16:26 mysql_install_db
[root@localhost scripts] # ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/
 
Installing MySQL system tables...2016-01-13 17:24:23 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation  for  more  details).
2016-01-13 17:24:23 0 [Note]  /usr/local/mysql/bin/mysqld  (mysqld 5.6.25) starting as process 17643 ...
2016-01-13 17:24:23 17643 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-13 17:24:23 17643 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-13 17:24:23 17643 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-13 17:24:23 17643 [Note] InnoDB: Memory barrier is not used
2016-01-13 17:24:23 17643 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-13 17:24:23 17643 [Note] InnoDB: Using CPU crc32 instructions
2016-01-13 17:24:23 17643 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-13 17:24:23 17643 [Note] InnoDB: Completed initialization of buffer pool
2016-01-13 17:24:23 17643 [Note] InnoDB: Highest supported  file  format  is Barracuda.
2016-01-13 17:24:24 17643 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-13 17:24:24 17643 [Note] InnoDB: Waiting  for  purge to start
2016-01-13 17:24:24 17643 [Note] InnoDB: 5.6.25 started; log sequence number 1625987
2016-01-13 17:24:27 17643 [Note] Binlog end
2016-01-13 17:24:27 17643 [Note] InnoDB: FTS optimize thread exiting.
2016-01-13 17:24:27 17643 [Note] InnoDB: Starting  shutdown ...
2016-01-13 17:24:29 17643 [Note] InnoDB: Shutdown completed; log sequence number 1625997
OK
Filling help tables...2016-01-13 17:24:29 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation  for  more  details).
2016-01-13 17:24:29 0 [Note]  /usr/local/mysql/bin/mysqld  (mysqld 5.6.25) starting as process 17666 ...
2016-01-13 17:24:29 17666 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-13 17:24:29 17666 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-13 17:24:29 17666 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-13 17:24:29 17666 [Note] InnoDB: Memory barrier is not used
2016-01-13 17:24:29 17666 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-13 17:24:29 17666 [Note] InnoDB: Using CPU crc32 instructions
2016-01-13 17:24:29 17666 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-13 17:24:29 17666 [Note] InnoDB: Completed initialization of buffer pool
2016-01-13 17:24:29 17666 [Note] InnoDB: Highest supported  file  format  is Barracuda.
2016-01-13 17:24:29 17666 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-13 17:24:29 17666 [Note] InnoDB: Waiting  for  purge to start
2016-01-13 17:24:29 17666 [Note] InnoDB: 5.6.25 started; log sequence number 1625997
2016-01-13 17:24:29 17666 [Note] Binlog end
2016-01-13 17:24:29 17666 [Note] InnoDB: FTS optimize thread exiting.
2016-01-13 17:24:29 17666 [Note] InnoDB: Starting  shutdown ...
2016-01-13 17:24:31 17666 [Note] InnoDB: Shutdown completed; log sequence number 1626007
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:
   /usr/local/mysql/bin/mysqladmin  -u root password  'new-password'
   /usr/local/mysql/bin/mysqladmin  -u root -h localhost.localdomain password  'new-password'
Alternatively you can run:
   /usr/local/mysql/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  . ;  /usr/local/mysql/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/
The latest information about MySQL is available on the web at
   http: //www .mysql.com
Support MySQL by buying support /licenses  at http: //shop .mysql.com
WARNING: Found existing config  file  /usr/local/mysql/my .cnf on the system.
Because this  file  might be  in  use, it was not replaced,
but was used  in  bootstrap (unless you used --defaults- file )
and when you later start the server.
The new default config  file  was created as  /usr/local/mysql/my-new .cnf,
please compare it with your  file  and take the changes you need.
WARNING: Default config  file  /etc/my .cnf exists on the system
This  file  will be  read  by default by the MySQL server
If you  do  not want to use this, either remove it, or use the
--defaults- file  argument to mysqld_safe when starting the server


#修改/etc/profile给MySQL添加PATH环境变量:

export PATH=$PATH:/usr/local/mysql/bin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
[root@localhost scripts] # vi /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
     case  ":${PATH}:"  in
         *: "$1" :*)
             ;;
         *)
             if  "$2"  "after"  ] ;  then
                 PATH=$PATH:$1
             else
                 PATH=$1:$PATH
             fi
     esac
}
if  [ -x  /usr/bin/id  ];  then
     if  [ -z  "$EUID"  ];  then
         # ksh workaround
         EUID=` id  -u`
         UID=` id  -ru`
     fi
     USER= "`id -un`"
     LOGNAME=$USER
     MAIL= "/var/spool/mail/$USER"
fi
# Path manipulation
if  "$EUID"  "0"  ];  then
     pathmunge  /sbin
     pathmunge  /usr/sbin
     pathmunge  /usr/local/sbin
else
     pathmunge  /usr/local/sbin  after
     pathmunge  /usr/sbin  after
     pathmunge  /sbin  after
fi
HOSTNAME=` /bin/hostname  2> /dev/null `
HISTSIZE=1000
if  "$HISTCONTROL"  "ignorespace"  ] ;  then
     export  HISTCONTROL=ignoreboth
else
     export  HISTCONTROL=ignoredups
fi
export  PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if  [ $UID -gt 199 ] && [  "`id -gn`"  "`id -un`"  ];  then
     umask  002
else
     umask  022
fi
for  in  /etc/profile .d/*.sh ;  do
     if  [ -r  "$i"  ];  then
         if  "${-#*i}"  !=  "$-"  ];  then
             "$i"
         else
             "$i"  > /dev/null  2>&1
         fi
     fi
done
unset  i
unset  -f pathmunge
 
export  PATH=$PATH: /usr/local/mysql/bin

#使配置文件生效

1
[root@localhost bin] #source /etc/profile


#mysql的配置文件拷贝到/etc

1
2
3
4
5
[root@hadoop2 mysql-5.6.25] # cd /usr/local/mysql/support-files/
[root@hadoop2 support-files] # cp my-default.cnf /etc/my.cnf 
cp : overwrite ` /etc/my .cnf'? y
[root@hadoop2 support-files] # cp mysql.server /etc/init.d/mysqld
[root@hadoop2 support-files] # chmod 755 /etc/init.d/mysqld

#修改/etc/my.cnf 添加如下语句:

 basedir = /usr/local/mysql

 datadir = /data/mysql

 port = 3306

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost scripts] # vi /etc/my.cnf 
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
  basedir =  /usr/local/mysql
  datadir =  /data/mysql
  port = 3306
# server_id = .....
# socket = .....

#编辑/etc/init.d/mysqld添加

basedir=/usr/local/mysql

datadir=/data/mysql

[root@localhost support-files]# vi /etc/init.d/mysqld 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind
# MySQL daemon start/stop script.
# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.
# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO
# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir= /usr/local/mysql
datadir= /data/mysql

#添加服务并自启动

1
2
3
chkconfig  --add mysqld
chkconfig mysqld on
chkconfig --list| grep  mysqld
1
<br data-filtered= "filtered" >

#启动数据库

1
2
[root@hadoop2 scripts] # /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

#设置root帐户的密码

1
mysqladmin -uroot password  "123456"

#进入mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@hadoop2 scripts] # mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 1
Server version: 5.6.25 Source distribution
 
Copyright (c) 2000, 2015, 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> use mysql
Reading table information  for  completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql>

#删除用于本机匿名连接的空密码帐号

1
2
mysql>delete from user where password= "" ;
mysql>flush privileges;

#更改root的密码:

1
2
3
4
5
6
7
8
mysql>  update user  set  password=password( '123456' ) where user= 'root' ;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0
mysql> commit
     -> ;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

#创建用户mysql:

1
2
mysql>  create user  'mysql'  identified by  '123456' ;
Query OK, 0 rows affected (0.00 sec)


#给mysql用户赋权限:

1
2
3
4
mysql> GRANT ALL PRIVILEGES ON `mysql`.* TO  'mysql' @ '%' ;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


#打开后给其他机子的一个权限

1
2
3
4
mysql>insert into user(Host,User,passWord)  values( '%' , 'root@%' ,password( '123456' ));
mysql>grant all privileges on *.* to  root identified by  '123456' ;
mysql>grant all privileges on *.* to   'root@%'  identified by  '123456' ;
mysql>quit

#加入启动项

1
chkconfig mysqld on




卸载mysql

1.关闭目前的mysql服务

1
     /etc/init .d /mysqld  stop

2.确保已正常关闭

1
    ps  -ef |  grep  mysql

   如果没关闭,kill

3. 查询mysql的安装情况:

1
     rpm -qa |  grep  mysql

4   将列出来的删除。

1
2
3
4
  
rpm -e --nodeps 
包名

如果报有多个,则用项 --allmatches将其全部删掉



本文转自 lqbyz 51CTO博客,原文链接:http://blog.51cto.com/liqingbiao/1715943

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
关系型数据库 MySQL Linux
在Linux系统上实现高效安装与部署环境的全方位指南
在Linux系统上实现高效安装与部署环境的全方位指南
|
1天前
|
关系型数据库 MySQL 数据库
龙蜥操作系统上安装MySQL:步骤详解与常见问题解决
龙蜥操作系统上安装MySQL:步骤详解与常见问题解决
|
1天前
|
NoSQL Linux Redis
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
12 0
|
1天前
|
Ubuntu 安全 Linux
linux系统详细安装过程,都在这里了
linux系统详细安装过程,都在这里了
7 0
|
1天前
|
关系型数据库 MySQL Linux
在Centos7中:通过Docker安装MySQL5.7(保姆级)
在Centos7中:通过Docker安装MySQL5.7(保姆级)
|
1天前
|
JSON Linux 数据格式
在宝塔Linux中安装Docker
在宝塔Linux中安装Docker
|
1天前
|
编解码 安全 关系型数据库
祝福CSDN的小伙伴2024年快乐!Windows7安装MySQL
祝福CSDN的小伙伴2024年快乐!Windows7安装MySQL
|
1天前
|
存储 Oracle 关系型数据库
oracle 数据库 迁移 mysql数据库
将 Oracle 数据库迁移到 MySQL 是一项复杂的任务,因为这两种数据库管理系统具有不同的架构、语法和功能。
10 0
|
8天前
|
关系型数据库 MySQL Linux
【MySQL-10】数据库函数-案例演示【字符串/数值/日期/流程控制函数】(代码演示&可cv代码)
【MySQL-10】数据库函数-案例演示【字符串/数值/日期/流程控制函数】(代码演示&可cv代码)
【MySQL-10】数据库函数-案例演示【字符串/数值/日期/流程控制函数】(代码演示&可cv代码)
|
8天前
|
SQL 关系型数据库 MySQL
【MySQL-5】DDL的数据库操作:查询&创建&删除&使用(可cv代码+演示图)
【MySQL-5】DDL的数据库操作:查询&创建&删除&使用(可cv代码+演示图)