码迷,mamicode.com
首页 > 数据库 > 详细

centos 下安装mysql

时间:2014-07-29 11:29:16      阅读:406      评论:0      收藏:0      [点我收藏+]

标签:blog   http   os   strong   文件   数据   io   2014   

一.在线安装

  yum list | grep mysql

    显示yum服务器上mysql的版本信息

bubuko.com,布布扣

通过如下命令进行安装:

  yum install -y mysql-server mysql mysql-devel

安装完成后通过如下命令进行查看安装的版本号

  rpm -qi mysql-server

服务器的相关配置

  service mysqld start    #开启服务器

  service mysqld restart    #重启服务器

  service mysqld stop    #关闭服务器

  chkconfig --list | grep mysqld    #查看mysqld是否开机启动

  chkconfig mysqld on    #设置开机启动mysql

  mysqladmin -u root password ‘root‘  # 通过该命令给root账号设置密码为 root

  mysql -u root -p    #登陆数据库

  /etc/my.cnf 这是mysql的主配置文件

  /var/lib/mysql   mysql数据库的数据库文件存放位置

二、源码编译安装

1、下载安装编译MySQL源码需要的库
sudo apt-get install build-essential libncurses5-dev cmake
2、添加mysql用户组和用户
groupadd mysql
useradd -g mysql mysql
3、创建MySQL软件安装目录和数据存放目录
mkdir -p /opt/mysql #MySQL安装目录
chown -R mysql:mysql /opt/mysql
mkdir -p /data/mysql #MySQL数据存放目录
mkdir -p /data/mysql/data #存放数据
mkdir -p /data/mysql/log #存放日志
mkdir -p /data/mysql/tmp #存放临时文件
chown -R mysql:mysql /data/mysql

4、cmake编译安装MySQL
tar -zxvf mysql-5.6.13.tar.gz
cd mysql-5.6.13
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/opt/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
make
make install
参数说明:
-DCMAKE_INSTALL_PREFIX=/opt/mysql //指定安装目录
-DINSTALL_DATADIR=/data/mysql //指定数据存放目录
-DSYSCONFDIR=/opt/mysql //指定配置文件目录(本例的配置文件为/opt/mysql/my.cnf)
-DDEFAULT_CHARSET=utf8 //指定字符集
-DDEFAULT_COLLATION=utf8_general_ci //指定校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
上述步骤执行成功后,MySQL软件已成功安装至/opt/mysql目录下。

5、编辑配置文件my.cnf
[client]
port = 3306
socket = /opt/mysql/run/mysql.sock

[mysql]

[mysqld_safe]
pid-file = /opt/mysql/run/mysqld.pid
socket = /opt/mysql/run/mysql.sock
nice = 0

[mysqld]

#### Baes dir ####
basedir = /opt/mysql
datadir = /data/mysql/data
tmpdir = /data/mysql/tmp
socket = /opt/mysql/run/mysql.sock
user=mysql
#### Base configure info ####
port = 3306

skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
log-error = /data/mysql/log/alert.log
slow_query_log_file= /data/mysql/log/slow.log
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes

#### Binary log && Relay log ####
#binlog_format=‘MIXED‘
log-bin = /data/mysql/log/mysql-bin
log-slave-updates = 1
relay-log = /data/mysql/log/mysqld-relay-bin
relay-log-index = /data/mysql/log/mysqld-relay-bin.index
master-info-file = /data/mysql/log/master.info
relay-log-info-file = /data/mysql/log/relay-log.info
max_binlog_size = 100M

[mysqldump]
quick
quote-names
max_allowed_packet = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer = 16M
6、创建数据库
/opt/mysql/scripts/mysql_install_db --user=mysql --explicit_defaults_for_timestamp --basedir=/opt/mysql/
上述建库语句将根据my.cnf里设置的数据文件目录和日志文件目录,生成相应的数据文件和日志文件,并创建系统数据库(如mysql,test,information_schema,performance_schema)
7、启动MySQL
/opt/mysql/support-files/mysql.server start
启动成功后,就可以以root用户登录(默认的root用户没有密码)
/opt/mysql/bin/mysql -u root
查看是否可以登录
8、设置root密码
mysqladmin -u root password ‘123456a?‘
mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456a?‘ WITH GRANT OPTION;

9、最后,把MySQL加入系统启动项和开机启动
在/etc/profile 文件中增加
export PATH=$PATH:/opt/mysql/bin
cp ./support-files/mysql.server /etc/init.d/mysqld #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld #增加执行权限
update-rc.d -f mysqld defaults #加入开机启动

 

centos 下安装mysql,布布扣,bubuko.com

centos 下安装mysql

标签:blog   http   os   strong   文件   数据   io   2014   

原文地址:http://www.cnblogs.com/s-hk/p/3874076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!