mysql系列之三MySQL编译安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql系列之三MySQL编译安装相关的知识,希望对你有一定的参考价值。
mysql 安装:
专用软件包管理器包
deb,rpm
rpm:
RHEL(Oracle Linux),CentOS
SUSE
通用二进制格式包
gcc:x86,x64
源代码
5.5,5.6
cmake编译
选择GA版本
mysql-client提供客户端
mysql-devel开发组建
mysql-server服务器端
mysql-shared共享库
mysql-shared-compat兼容库
mysql-test 测试组件
最后一次读取的配置优先级最高
/etc/my.cnf
/etc/mysql/my.conf
$MYSQL_HOME/my.conf
/path/to/file when defaults-extra-file=/path/to/file is specified
~/.my.conf
----------------------
用户密码修改
1.mysqladmin -u USERNAME -h HOSTNAME password ‘NEW_PASSWORD‘ -p
2.mysql>set password for ‘USERNAME‘@‘HOST=PASSWORD(‘new_pass‘);
3.mysql>update mysql.user set password=password(‘NEW_PASS‘) where condition;
一安装编译mysql-5.5
1.使用cmake编译mysql-5.5
cmake 指定编译选项的方式不同于make,其实现方式对比如下:
./configure = cmake .
./configure --help = cmake . LH 或者 ccmake .
指定安装文件的安装路径时常用的选项:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql
-DSYSCONFDIR=/etc
默认编译的存储引擎包括:csv,myisam,myisammrg和heap:若要安装其他存储引擎,可以使用类似如下编译选项:
-DWITH_INNOBASE_STOAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
_DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
若要明确指定不编译某存储引擎,可以使用类似如下的选项:
-DWITH_<ENGiNE>_STORAGE_ENGINE=1
比如:
-DWITH_EXAMPLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
如若要编译进其他功能,如SSL等,则可使用类似如下选项来实现编译时使用某库或不使用某库:
-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1
比如:
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
如若要编译进其他功能,如ssl等,则可以使用类似如下选秀爱那个来实现编译时使用某库或不使用某库:
-DWITH_READLIE=1
-DWITH_SSL=system
-DWITH_ZLIB=system
-DWITH_LIBWRAP=0
其他常用选项:
_DMYSQL_TCP_PORT=3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DENABLED_LOcAL_INFILE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0
-DENABLE_PROFILING=1
如果想清理此前的编译所生成的文件,则需要使用如下命令:
make clean
rm CMakeCache.txt
2.编译安装
groupadd -r mysql
useradd -g mysql -r -d /data/mydata mysql
tar xf mysql-5.6
cd mysql-5.6
cmake . -DCMAKE_INSALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
make
make install
安装:
[[email protected] ~]# yum -y groupinstall ‘Development tools‘
[[email protected] ~]# hwclock -s
[[email protected] ~]# tar xf mysql-5.5.28.tar.gz
[[email protected] cmake-2.8.8]# ./configure && make && make install
[[email protected] ~]# fdisk /dev/sdb 新建一个分区,并调整分区类型为8e
/dev/sdb1 1 2610 20964793+ 8e Linux LVM
[[email protected] ~]# partprobe /dev/sdb让系统重读分区 或者重启
[[email protected] ~]# pvcreate /dev/sdb1
[[email protected] ~]# vgcreate myvg /dev/sdb1
[[email protected] ~]# lvcreate -L 10G -n mydata myvg
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
mydata myvg -wi-a----- 10.00g
[[email protected] ~]# mke2fs -j /dev/myvg/mydata
[[email protected] ~]# mkdir /mydata
[[email protected] ~]# vim /etc/fstab
/dev/myvg/mydata /mydata ext3 defaults 0 0
[[email protected] ~]# mkdir /mydata/data
[[email protected] ~]# groupadd -r mysql
[[email protected] ~]# useradd -r -g mysql -s /sbin/nologin mysql
[[email protected] ~]# chown -R mysql.mysql /mydata/data/
[[email protected] mysql-5.5.28]# yum install –y openssl openssl-devel ncurses ncurses-devel
[[email protected] mysql-5.5.28]# cmake . -DCMAKE_INSALL_PREFIX=/usr/local/mysql \
> -DMYSQL_DATADIR=/mydata/data \
> -DSYSCONFDIR=/etc \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DWITH_SSL=system \
> -DWITH_ZLIB=system \
> -DWITH_LIBWRAP=0 \
> -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
[[email protected] mysql-5.5.28]# make && make install
[[email protected] local]# chown -R mysql.mysql mysql
[[email protected] local]# chown -R mysql.mysql /mydata/
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mydata/data 初始化数据库
[[email protected]host mysql]# cp support-files/my-large.cnf /etc/my.cnf 复制配置文件
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld 复制启动脚本
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld on
[[email protected] mysql]# vim /etc/my.cnf
# Try number of CPU‘s*2 for thread_concurrency
thread_concurrency = 8
datadir = /mydata/data
[[email protected] mysql]# vim /etc/profile.d/mysql.sh 添加环境变量
export PATH=$PATH:/usr/local/mysql/bin
[[email protected] mysql]# . /etc/profile.d/mysql.sh
[[email protected] mysql]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
[[email protected] mysql]# mysql
mysql> show databases; 可以查看数据库
mysql> show engines; 查看存储引擎
给mysql管理用户添加密码。
先删除默认用户:
mysql> show databases;
mysql> USE mysql;
mysql> show tables;
mysql> select user,host,password from user;
+------+-----------------------+----------+
| user | host | password |
+------+-----------------------+----------+
| root | localhost | |
| root | localhost.localdomain | |
| root | 127.0.0.1 | |
| root | ::1 |ipv6的帐号|
| | localhost.localdomain | 删除 |
+------+-----------------------+----------+
5 rows in set (0.00 sec)
mysql> DROP USER ‘‘@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ‘‘@localhost.localdomain;
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ‘root‘@‘::1‘;
Query OK, 0 rows affected (0.00 sec)
mysql> update user set password=PASSWORD(‘root‘) where user=‘root‘;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select user,host,password from user;
+------+---------------------------+-------------------------------------------+
| user | host | password |
+------+---------------------------+-------------------------------------------+
| root | localhost.localhostdomain | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | 127.0.0.1 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+------+---------------------------+-------------------------------------------+
1 row in set (0.00 sec)
mysql>
mysql ->mysqld
Unix:
mysql->mysql.sock->mysqld
Windows:
mysql->memory(pipe)->mysqld
不在同一主机上,基于TCP/IP协议
mysql
-uroot -h 192.168.1.50 TCP/IP协议
客户端工具:
mysql
mysqldump备份工具
mysqladmin管理工具
mysqlcheck检查数据库完整性工具
[client]
-u USERNAME
-h HOST
-p ‘PASSWS‘
--protocol {tcp|socket|pipe|memory}
--port PORT
非客户端工具:
myisamchk
myisampack
myisam:
每表三个文件
.frm:表结构
.MYD:表数据
.MYI:表索引
InnoDB
所有表共享一个表空间文件;
建议每个独立的表空间文件;
.frm:表结构
.ibd表空间(表数据和表索引)
mysqlimport
mysql> show variables like ‘%innodb%‘; 查看innodb变量
vim /etc/my.conf
innodb_file_per_table = 1
service mysqld restart
mysql> create database mydb;
mysql> create table testdb (
-> id INT NOTNULL,
-> name CHAR(30);
/mydata/data/mysql/mydb/
db.opt test.db.frm test.ibd
本文出自 “运维成长路” 博客,谢绝转载!
以上是关于mysql系列之三MySQL编译安装的主要内容,如果未能解决你的问题,请参考以下文章