赞
踩
一、数据库技术构成
1. 数据库系统 DBS
数据库管理系统(DataBase Management System, DBMS): ORACLE、MySQL、DB2
2. SQL语言(结构化查询语言)
A. DDL语句 数据库定义语言: 数据库、表、视图、索引、存储过程、函数, CREATE DROP ALTER
B. DML语句 数据库操纵语言: 插入数据INSERT、删除数据DELETE、更新数据UPDATE、查询数据 SELECT
C. DCL语句 数据库控制语言: 例如控制用户的访问权限GRANT、REVOKE
3. 数据访问技术
A. ODBC PHP <.php>
B. JDBC JAVA <.jsp>
二、RPM安装
1、相关软件包
mysql-community-client-5.7.18-1.el7.x86_64.rpm 客户端
mysql-community-devel-5.7.18-1.el7.x86_64.rpm 开发库
mysql-community-embedded-5.7.18-1.el7.x86_64.rpm 嵌入式
mysql-community-server-5.7.18-1.el7.x86_64.rpm 服务端
mysql-community-libs-5.7.18-1.el7.x86_64.rpm 共享库
mysql-community-test-5.7.18-1.el7.x86_64.rpm 测试组件
由于RHEL7以后安装光盘不再提供MySQL,可以将所有的RPM包下载下来安装,也可以配置 MySQL官方提供的YUM源文件。https://dev.mysql.com/downloads/repo/yum/
2、yum源方式下载
# yum install -y https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
# yum list | grep "mysql-community" //查询MySQl包;
mysql-community-client.i686 5.7.19-1.el7 mysql57-community
mysql-community-client.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-common.i686 5.7.19-1.el7 mysql57-community
mysql-community-common.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-devel.i686 5.7.19-1.el7 mysql57-community
mysql-community-devel.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-embedded.i686 5.7.19-1.el7 mysql57-community
mysql-community-embedded.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-embedded-compat.i686 5.7.19-1.el7 mysql57-community
mysql-community-embedded-compat.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-embedded-devel.i686 5.7.19-1.el7 mysql57-community
mysql-community-embedded-devel.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-libs.i686 5.7.19-1.el7 mysql57-community
mysql-community-libs.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-libs-compat.i686 5.7.19-1.el7 mysql57-community
mysql-community-libs-compat.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-release.noarch el7-7 mysql57-community
mysql-community-server.x86_64 5.7.19-1.el7 mysql57-community
mysql-community-test.x86_64 5.7.19-1.el7 mysql57-community
注意:安装MySQL yum install mysql-community-client mysql-community-server 时需要卸载 mariadb-libs等包。CentOS7系统支持MariaDB数据库;
三、安装MySQL RPM包安装方式:
1、安装步骤:
1、卸载Mariadb # rpm -e mariadb-libs postfix
2、安装 # yum localinstall mysql-community-client-5.7.18-1.el7.x86_64.rpm mysql-community-server-5.7.18-1.el7.x86_64.rpm mysql-community-libs-5.7.18-1.el7.x86_64.rpm mysql-community-common-5.7.18-1.el7.x86_64.rpm
2、启动MySQL服务:
# systemctl start mysqld
# systemctl enable mysqld
3、查看MySQL默认密码:
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
# grep "temporary password" /var/log/mysqld.log
2017-08-04T15:14:25.922138Z 1 [Note] A temporary password is generated for root@localhost: Ng21WK5INA_x (默认密码为:Ng21WK5INA_x)
4、登陆MySQL:
mysql -uroot -p
修改MySQL密码:
alter user 'root'@'localhost' identified by 'ABC123,com';
四、使用MySQL(Linux - Generic)二进制安装:
1、下载glibc版本的MySQL : https://downloads.mysql.com/archives/community/
mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
2、新建用户以安全方式运行进程
# groupadd -r -g 36 mysql
# useradd -r -u 36 -g 36 -s /sbin/nolgin -M mysql
3、安装并初始化mysql
# tar xvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# ln -sv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql
# chown -R mysql.mysql mysql/*
初始化
# cd mysql
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data
记住密钥:
A temporary password is generated for root@localhost: rlrrF!tk>2d=
4、 新建mysql主配置文件/etc/my.cnf 默认配置文件:support-files/ my-default.cnf
#cp support-files/ my-default.cnf /etc/my.cnf
# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
server_id=10
port = 3306
user = mysql
character-set-server = utf8
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysqld.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
#####====================================
[innodb]
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:1024M:autoextend
#####====================================[log]==============================
log_error = /var/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql-slow.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
5、修改MySQL sysv服务脚本
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
6、启动MySQL
# chkconfig --add mysqld #添加为系统服务
# chkconfig mysqld on #开机自启动
# systemctl start mysqld
7、将MySQL 的bin目录加入PATH环境变量,编辑/etc/profile文件 使用mysql客户端命令
方法1:使用绝对路径 # /usr/local/mysql/bin/mysql
方法2:添加环境变量
# cd /etc/profile.d/
# vim mysql.sh
export PATH=$PATH:/usr/local/mysql/bin //添加内容
# source mysql.sh
8、修改MySQL密码:
alter user 'root'@'localhost' identified by 'ABC123,com';
五、源码安装:
说明:从5.5开始使用cmake编译。在mysql5.7后编译安装需要boost的支持
Boost库:一个开源可移植的C++库,是C++标准化进程的开发引擎之一。
1、安装开发工具和开发包
# yum install gcc-c++ cmake ncurses-devel
2、编译安装MySQL
1)解压 # tar xf mysql-boost-5.7.18.tar.gz -C /usr/local/src/
2)使用cmake编译MySQL
备注:cmake指定编译选项的方式不同于make,其实现方式对比如下:
./configure cmake .
./configure --help cmake . -LH or ccmake .
注意:如果想清理此前的编译所生成的文件重新编译,则需要使用如下两条命令:
make clean;
rm CMakeCache.txt 清理缓存文件
3、编译MySQL文件:
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_INNODB_MEMCACHED=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_BOOST=boost
cmake参数:https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html
4)编译安装 # make && make install
5、新建mysql主配置文件/etc/my.cnf 默认配置文件:support-files/ my-default.cnf
#cp support-files/ my-default.cnf /etc/my.cnf
# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
# port = .....
socket = /tmp/mysql.sock
symbolic-links=0
[mysqld_safe]
pid-file = /usr/local/mysql/mysqld/pid
log_error = /usr/local/mysql/mysql_error.log
character_set_server=utf8
6、初始化 创建用户
# groupadd -g 36 mysql
# useradd -r -u 36 -g 36 -s /sbin/nolgin -M mysql
创建数据库存放目录并授权
# mkdir /usr/local/mysql/data -p
# chown -R mysql.mysql /usr/local/mysql/data
初始化mysql
# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
7、为mysql提供sysv服务脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
8、修改PATH环境变量,让系统可以直接使用mysql的相关命令l
# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
# source mysql.sh
启动MySQL:# systemctl start mysql
9、修改MySQL密码:
alter user 'root'@'localhost' identified by 'ABC123,com';
六、验证服务器:
测试来检查服务器是否已启动并响应连接
#bin/mysqladmin version # bin/mysqladmin variables
#bin/mysqladmin -u root -p version
使用mysqlshow查看存在的数据库:
#mysqlshow -uroot -p
mysqlshow -uroot -p mysql(数据库表名)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。