今天来记录下搭建mysql的过程,搭建方法有三种分别是rpm包,二进制和源码编译三种方法,由于rpm包的安装方式局限行比较大,不一定适合当前生产环境,所以一般不采用这种方法,更多的是采用二进制和源码编译的方法。我这次用二进制的方式安装
安装环境:
安装环境: Asianux3 内核版本:Asianux 3.1
软件包: 官网下载的V77250-01.zip
mysql-advanced-5.6.26-linux-glibc2.5-i686.tar.gz
安装步骤:
1.环境准备,gcc gcc-c++,开发工具,开发库,什么的
2.查看当前系统是否安装mysql服务
#rpm -qa mysql
mysql-5.0.45-7.1AXS3
查到系统自带安装有mysql,怎么办?卸载
#yum -y remove mysql*
#rpm -qa mysql //卸载成功
3.开始安装 mysql-5.6
#unzip V77250-01.zip //解压官网下载的软件包
#tar zxf mysql-advanced-5.6.26-linux-glibc2.5-i686.tar.gz -C /usr/local/
//再此注意:官网要求必须解压到 /usr/local/目录下
#ls /usr/local/ //会有和包名一样的目录
bin mysql-advanced-5.6.26-linux-glibc2.5-i686 etc nginx
# ln -sv mysql-advanced-5.6.26-linux-glibc2.5-i686 mysql
//创建数据库链接,不要改目录的名字
4.创建mysql用户和组
#groupadd -r -g 306 mysq //创建mysql组
#useradd -g306 -r -u 306 mysql // 创建mysql系统用户
#id mysql //验证结果
uid=306(mysql) gid=306(mysql) groups=306(mysql)
5.修改mysql、下的文件属组和属主,并初始化数据库
#chown -R mysql.mysql /usr/local/mysql/*
#/usr/local/mysql/scripts/mysql_install_db --user=mysql
//初始化必须指定用户为mysql用户
但是为了防止数据库被突破后,都能取得mysql文件的所有权,这样是很危险的所以
#chown -R root /usr/local/mysql/*
//修改所有文件属组为root
#chown -R mysql.mysql /usr/local/mysql/data/
//修改data目录的都为mysql,因为默认数据是存在data目录的,mysql用户要对这个目录有所有权
6.准备启动脚本,在安装目录下的support-files目录下有mysql-server脚本
#cp support-files/mysql.server /etc/init.d/mysqld
//拷贝到etc下
#ls -l /etc/init.d/mysqld //验证结果
#chkconfig --add mysqld //添加到开机启动
#chkconfig --list mysqld //查看启动状态
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5: 启用 6: 关闭
7.准备主配置文件
#cp support-files/my-default.cnf /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 = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
8.现在可以启动服务了
#service mysqld start
#netstat -anput |grep nysql
tcp 0 0 :::3306 :::* LISTEN 4248/mysqld
//启动成功有3306端口
9.连接数据库
#mysql //提示没有这个命令
解决办法:
# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
//加入mysql的脚本路径
10.再次连接
#mysql
bin/mysql: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory
//这是什么情况,还是连接不上
解决办法:
原因是:刚开始的时候卸载了所有mysql依赖的软件包,包括mysqlclient,所以才会提示找不到
重新挂载光盘,mount 进入到挂载目录,找到rpm包目录,查找mysql的rpm软件包
#cd /medir/Asianux/Asianux/RPMS
#ls |grep mysql*
#rpm -ivh mysql*
连接试试,又报错
[mysql]ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
//说sock文件路径不对
解决办法:
#mkdir /var/lib/mysql //创建sock文件目录
#ln -sv /tmn/mysql.sock /var/lib/mysql/mysql.sock
//做sock文件路径链接
再试试连接数据库
#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.15 sec)
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> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
28 rows in set (0.01 sec)
这下终于好了,连接成功了查看下数据库的版本
# mysql -V
mysql Ver 14.14 Distrib 5.6.26, for linux-glibc2.5 (i686) using EditLine wrapper
//版本是5.6
其实mysql本身带有安装方法:
路径就是:# head -n 110 /usr/local/mysql/INSTALL-BINARY
这是其中的一部分,关于安装方法的。
To install and use a MySQL binary distribution, the command
sequence looks like this:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
这是第一次使用二进制安装mysql,而且还是新版的mysql。如果有错误还望大家提出,以后好改进。