标签:general base mon insecure file 关闭 ble ase server
mysql服务基础:mysql是一个真正的多线程、多用户的SQL数据库服务,凭借其高性能、高可靠和易于使用的特性,成为服务器领域中最受欢迎的开源数据库系统。
MySQL的编译安装:
1.安装支持软件
yum install gcc gcc-c++ ncurses ncurses-devel cmake -y
2.创建运行用户mysql,并解压mysql源码包到/opt/目录下,将boost源码包解压到/usr/local/ 目录下,将解压后的boost包重命名方便管理。
useradd -s /sbin/nologin mysql
tar zxvf mysql-5.7.17.tar.gz -C /opt/
tar zxvf boost_1_59_0.tar.gz -C /usr/local/
cd /usr/local/
mv boost_1_59_0 boost
3.在配置过程中,可以将默认使用的字符集设置为utf8,并添加其他字符集的支持。
cd mysql-5.7.17/
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //安装目录//
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \ //指定初始化参数文件目录//
-DSYSTEMD_PID_DIR=/usr/local/mysql -DDEFAULT_CHARSET=utf8 \ //指定默认使用的字符集编码//
-DDEFAULT_COLLATION=utf8_general_ci \ //适用于UTF-8字符集的通用规则//
-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost \ //指定Boost库的位置,5.7版本必须添加这个参数
-DWITH_SYSTEMD=1
------注意:如果在CMAKE的过程中有报错,当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧------------
4.编译并安装
make
make install
------注意:如果在make加载过程中,中途卡死,把虚拟机的内存设置为2G,再进行make编译//,如果再make编译过程中出现error报错,可用以下方法解决:下载mysql-boost-5.7包并进行解压,在进行配置,把boost函数库位置由-DWITH_BOOST=/usr/local/boost \改为-DWITH_BOOST=boost \
5.对数据库的目录进行权限设置
chown -R mysql.mysql /usr/local/mysql/
6.在MySQL源码目录中的support-files文件夹下,建立MySQL系统的/etc/my.cnf配置文件。
vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
7.修改/etc/my.cnf即主配置文件的属主和属组
chown mysql:mysql /etc/my.cnf
8.设置环境变量,为了方便在任何目录下使用mysql命令,需要在/etc/profile设置环境变量。
echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profile
echo ‘export PATH‘ >> /etc/profile
source /etc/profile //开启//
9.初始化数据库,为了能够正常使用MySQL数据库系统,应以运行用户mysql的身份执行初始化,指定数据存放目录等。
cd /usr/local/mysql/
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
10.添加mysqld系统服务,以便通过systemctl进行管理,可以直接使用源码包中提供的服务脚本。找到usr/lib/systemd/system/文件夹下的mysql.server脚本文件,将其复制到/usr/lib/systemd/目录下,并改名为system,然后再进行重新加载。
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload //重新加载系统服务管理模块
11.启动mysqld服务并查看TCP3306端口是否开启
systemctl start mysqld
netstat -anpt | grep 3306
[root@localhost mysql]# netstat -anpt | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 23765/mysqld
12.关闭防火墙
systemctl stop firewalld.service
setenforce 0
13.设置数据库的root登录密码
mysqladmin -u root -p password "abc123"
14.登录数据库
[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, 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> grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘abc123‘ with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
15.查看数据库结构
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
标签:general base mon insecure file 关闭 ble ase server
原文地址:http://blog.51cto.com/13642258/2133196