暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Linux编译安装MySQL5.5

大碗岛星期天下午的梦 2018-01-30
327

MySQL发行产品主要有三种,MySQL5.4之前,MySQL5.4至5.7,MySQL6.0至7.1,其中市面上大多数互联网公司用的是MySQL5.4至M5.7版本,也叫GA(Generally Available Release)版。三种产品是在一定原始基础上发展的三个独立方向,不存在承接关系。本文装的是GA版。


1.安装环境

[root@gaga data]# cat /etc/issue

Red Hat Enterprise Linux Server release 6.9 (Santiago)

Kernel \r on an \m

[root@gaga data]# uname -r

2.6.32-696.el6.x86_6


2.安装编译工具cmake

[root@gaga data]# tar xf cmake-2.8.8.tar.gz

[root@gaga cmake-2.8.8]#cd cmake-2.8.8

[root@gaga cmake-2.8.8]#./configure  

-- Enable ninja generator.

-- Configuring done

-- Generating done

-- Build files have been written to: /data/cmake-2.8.8

---------------------------------------------

CMake has bootstrapped.  Now run gmake.

[root@gaga cmake-2.8.8]#gmake && gmake install


3.安装依赖和用户、用户组

[root@gaga data]# yum install -y ncurses-devel

[root@gaga data]#groupadd mysql

[root@gaga data]#useradd mysql -s /sbin/nologin -M -g mysql


4.编译mysql

[root@gaga data]#tar xf mysql-5.5.32.tar.gz

[root@gaga data]#cd mysql-5.5.32

[root@gaga mysql-5.5.32]# cmake . -DCMAKE_INSTALL_PREFIX=/data/mysql-5.5.32 \

-DMYSQL_DATADIR=/data/mysql-5.5.32/data \

-DMYSQL_UNIX_ADDR=/data/mysql-5.5.32/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \

-DWITH_FAST_MUTEXES=1 \

-DWITH_ZLIB=bundled \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_READLINE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DWITH_DEBUG=0

[root@gaga mysql-5.5.32]# make && make install


5.拷贝配置文件、设置环境变量、设置链接

[root@gaga support-files] # ln -s /data/mysql-5.5.32/ /data/mysql

[root@gaga support-files] #cp /data/mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf

cp: overwrite `/etc/my.cnf'? y

[root@gaga support-files]# echo 'export PATH=/data/mysql/bin:$PATH' >> /etc/profile 

[root@gaga support-files]# source /etc/profile

[root@gaga support-files]# tail -1 /etc/profile

export PATH=/data/mysql/bin:$PATH


6.初始化mysql和设置目录权限

[root@gaga mysql-5.5.32]# chown -R mysql:mysql /data/mysql/data/

[root@gaga mysql-5.5.32]# chmod -R 1777 /tmp/

[root@gaga mysql-5.5.32]#cd scripts/

[root@gaga scripts]# ./mysql_install_db --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql

WARNING: The host 'gaga' could not be looked up with resolveip.

This probably means that your libc libraries are not 100 % compatible

with this binary MySQL version. The MySQL daemon, mysqld, should work

normally with the exception that host name resolving will not work.

This means that you should use IP addresses instead of hostnames

when specifying MySQL privileges !

Installing MySQL system tables...

OK

Filling help tables...

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:


/data/mysql/bin/mysqladmin -u root password 'new-password'

/data/mysql/bin/mysqladmin -u root -h gaga password 'new-password'


Alternatively you can run:

/data/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 /data/mysql ; /data/mysql/bin/mysqld_safe &


You can test the MySQL daemon with mysql-test-run.pl

cd /data/mysql/mysql-test ; perl mysql-test-run.pl


Please report any problems with the /data/mysql/scripts/mysqlbug script!


7.修改mysql用户密码

[root@gaga data]# /data/mysql/bin/mysqladmin -u root password '1qaz@WSX'

[root@gaga data]#mysql -uroot -p1qaz@WSX

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.5.32 Source distribution


Copyright (c) 2000, 2013, 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>


8.删除一些user、host、database

mysql> select user,host from mysql.user;

mysql> delete from mysql.user where user=' ';

mysql> delete from mysql.user where host='gaga';

mysql> delete from mysql.user where host='::1';

mysql> drop database test;

mysql> show databases;


[root@gaga scripts]# mysql -uroot -p1qaz@WSX

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.32 Source distribution


Copyright (c) 2000, 2013, 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>  select user,host from mysql.user;

+------+-----------+

| user | host      |

+------+-----------+

| root | 127.0.0.1 |

| root | ::1       |

|      | gaga      |

| root | gaga      |

|      | localhost |

| root | localhost |

+------+-----------+

6 rows in set (0.00 sec)


mysql>delete from mysql.user where user=' ';

Query OK, 2 rows affected (0.00 sec)


mysql> delete from mysql.user where host='gaga';

Query OK, 1 row affected (0.00 sec)


mysql> delete from mysql.user where host='::1';

Query OK, 1 row affected (0.00 sec)


mysql> select user,host from mysql.user;

+------+-----------+

| user | host      |

+------+-----------+

| root | 127.0.0.1 |

| root | localhost |

+------+-----------+

2 rows in set (0.00 sec)


mysql> drop database test;

Query OK, 0 rows affected (0.00 sec)


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

3 rows in set (0.00 sec)


mysql> quit

Bye

[root@gaga scripts]#


文章转载自大碗岛星期天下午的梦,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论