#创建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 i 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将其全部删掉