Mysql DBA 高级运维学习笔记-MySQL5.5编译方式安装实战
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql DBA 高级运维学习笔记-MySQL5.5编译方式安装实战相关的知识,希望对你有一定的参考价值。
本文为老男孩mysql DBA 高级运维课程学习笔记的第三节,感谢老男孩老师,我
是一个菜鸟如果有写的不正确的地方请各位大神及时指点。
4.源码cmake方式编译安装MySQL5.5.32
4.1 下载mysql安装包
MySQL从5.3开始使用cmake的安装方式。
本次实战选用mysql5.5.32
MySQL系列下载地址
http://dev.mysql.com/downloads/mysql/5.5.html#downloads
下载cmake
wget http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
4.2 查看系统环境
[[email protected] ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
[[email protected] ~]# uname -m
x86_64
[[email protected] ~]# uname -r
2.6.32-573.el6.x86_64
4.3 安装cmake
[[email protected] ~]# mkdir -p /home/zbf
[[email protected] ~]# mkdir -p /home/zbf/tools
[[email protected] ~]# cd /home/zbf/tools/
[[email protected] tools]# tar -zxf cmake-2.8.8.tar.gz
[[email protected] tools]# cd cmake-2.8.8
[[email protected] cmake-2.8.8]# ./configure
提示用gmake安装,用make也可以
[[email protected] cmake-2.8.8]# gmake
[[email protected] cmake-2.8.8]# gmake install
安装依赖包
[[email protected] tools]# yum install ncurses-devel -y
4.5 开始安装mysql
4.5.1 创建用户和组
[[email protected] tools]# groupadd mysql
[[email protected] tools]# useradd -g mysql mysql
4.5.2 解压编译mysql
[[email protected] tools]# tar -zxf mysql-5.5.32.tar.gz
[[email protected] tools]# cd mysql-5.5.32
[[email protected] mysql-5.5.32]#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql #指定安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data #指定数据存放目录重要
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock #指定sock路径
-DDEFAULT_CHARSET=utf8 #指定默认字符集
-DDEFAULT_COLLATION=utf8_general_ci #指定校准字符集编码
-DEXTRA_CHARSETS=all #安装所需字符集
-DENABLED_LOCAL_INFILE=ON #启用加载本地数据
-DWITH_INNOBASE_STORAGE_ENGINE=1 #支持innode引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1 #支持federated引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 #支持黑洞存储引擎
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 #支持安装数据库分区
-DWITH_FAST_MUTEXES=1
-DWITH_ZLIB=bundled #zlib压缩模式
-DENABLED_LOCAL_INFILE=1
-DWITH_READLINE=1
-DWITH_EMBEDDED_SERVER=1
-DWITH_DEBUG=0 #禁用debug,开启影响性能
[[email protected] mysql-5.5.32]# make && make install
[[email protected] mysql-5.5.32]# ln -s /home/zbf/tools/mysql-5.5.32 /usr/local/mysql/
特别说明:常规configure编译方式安装以及免编译方式安装等等的安装方法,都是上面的过程不同,下面相同。
4.5.3 初始化配置MySQL
4.5.3.1 查看默认模板配置文件
[[email protected] mysql-5.5.32]# ll support-files/my*cnf
-rw-r--r--. 1 root root 4723 1月 11 19:03 support-files/my-huge.cnf
-rw-r--r--. 1 root root 19791 1月 11 19:03 support-files/my-innodb-heavy-4G.cnf
-rw-r--r--. 1 root root 4697 1月 11 19:03 support-files/my-large.cnf
-rw-r--r--. 1 root root 4708 1月 11 19:03 support-files/my-medium.cnf
-rw-r--r--. 1 root root 2872 1月 11 19:03 support-files/my-small.cnf
4.5.3.2 选择配置文件
配置文件很多我们选一个小的,因为是测试环境
[[email protected] mysql-5.5.32]# cp support-files/my-small.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
4.5.3.3 配置环境变量
[[email protected] mysql-5.5.32]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile
[[email protected] mysql-5.5.32]# tail -1 /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[[email protected] mysql-5.5.32]# source /etc/profile
[[email protected] mysql-5.5.32]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
注意一定要把/usr/local/mysql/bin放在前边,因为在以后安装的系统里很可能有yum安装的客户端。如果不把/usr/local/
mysql/bin放在前边当我们输入mysql的时候它会调用系统rpm的mysql命令。这里有一个配置环境变量的例子,下面例子来自老男孩老师的博客。大家可以看一看 http://blog.51cto.com/oldboy/1122867。
4.5.3.4 初始化数据文件
#已经有了,没有的话创建一个mysql数据文件目录
[[email protected] mysql-5.5.32]# ll /usr/local/mysql/data/
总用量 4
drwxr-xr-x. 2 root root 4096 1月 11 19:17 test
#授权mysql用户访问mysql的安装目录
[[email protected] mysql-5.5.32]# chown -R mysql.mysql /usr/local/mysql/data/
#调整/tmp权限,否则初始化会错误
[[email protected] mysql-5.5.32]# chmod -R 1777 /tmp/
#初始化注意这个初始化和5.1不一样,在scripts下面
[[email protected] mysql-5.5.32]# cd /usr/local/mysql/scripts/
[[email protected] scripts]# ./mysql_install_db --basedir=/usr/local/
mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
现在mysql就安装完成了,安装完成之后我们一定要来看一下初始化的信息,因为它
给我们提示了很多信息。
Installing MySQL system tables...
######初始化成功的关键是有两个OK,一般有两个OK就说明初始化成功了,出现警告不用管
OK
Filling help tables...
OK
###这个是启动脚本,提示了copy启动脚本启动mysql
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:
#####mysql没有密码可以改密码
/usr/local/mysql//bin/mysqladmin -u root password ‘new-password‘
/usr/local/mysql//bin/mysqladmin -u root -h mysql 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.
####如果想启动mysql,可以用下面的方法启动
You can start the MySQL daemon with:
cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &
###如果想测试可以用这个方法测试
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl
###如果想汇报bug可以用这个方法汇报bug
Please report any problems with the /usr/local/mysql//scripts/mysqlbug script!
4.5.3.5 复制mysql启动脚本,启动mysql
[[email protected] mysql-5.5.32]# cp support-files/mysql.server /etc/
init.d/mysqld
[[email protected] mysql-5.5.32]# chmod +x /etc/init.d/mysqld
[[email protected] mysql-5.5.32]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[[email protected] ~]# chkconfig mysqld on
[[email protected] ~]# chkconfig --list mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
4.6 简单优化
4.6.1 清楚并修改管理员用户
ysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | mysql |
| root | mysql |
+------+-----------+
6 rows in set (0.01 sec)
mysql> delete from mysql.user where user="";
Query OK, 2 rows affected (0.07 sec)
mysql> delete from mysql.user where host="mysql";
Query OK, 1 row affected (0.00 sec)
mysql> delete from mysql.user where host="::1";
Query OK, 1 row affected (0.00 sec)
4.6.2 删除test库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.11 sec)
4.6.3 退出mysql ,为mysql修改密码
修改密码很简单前面的初始化信息已经说明了
[[email protected] ~]# /usr/local/mysql//bin/mysqladmin -u root
password ‘123456‘
[[email protected] ~]# mysql -uroot -p123456
以上是关于Mysql DBA 高级运维学习笔记-MySQL5.5编译方式安装实战的主要内容,如果未能解决你的问题,请参考以下文章
Mysql DBA 高级运维学习笔记-Mysql插入中文乱码问题
Mysql DBA 高级运维学习笔记-MySQL主从复制故障解决
Mysql DBA 高级运维学习笔记-索引知识及创建索引的多种方法实战