【第2章】MySQL数据库基于Centos七.叁-布置

发布时间:2019-04-26  栏目:NoSQL  评论:0 Comments

1、MySQL数据库的法定网站:

Centos六源码布署MySQL伍.6

mysql从5.5本子发轫,不再使用./configure编写翻译,而是采取cmake编写翻译器

mysql-5.陆.1陆.tar.gz源码包下载地址:
http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz

自己的mysql目录配置如下:
安装路径:/usr/local/mysql
数据库路线:/data/mysql
源码包存放地点:/usr/software

常备不懈专门的工作:安装基本依赖包,先用yum安装cmake、automake 、autoconf
,另MySQL 5.六.x亟待至少安装的包有:bison,gcc、gcc-c++、ncurses-devel
[[email protected]
~]# yum install cmake make -y
[[email protected]
~]# yum install gcc gcc-c++ autoconf bison automake zlib* fiex*
libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* -y
[[email protected]
~]# cp /root/mysql-5.6.15.tar.gz /usr/software/
[[email protected]
~]# cd /usr/software
初阶编译安装
[[email protected]
~]# tar -zxvf mysql-5.6.15.tar.gz
[[email protected]
~]# cd mysql-5.6.15
[[email protected]
~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql/ \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
[[email protected]
~]# make && make install

mysql官方网站英文文档简短翻译说Bellamy(Bellamy)下
The MyISAM, MEPRADOGE, MEMO福睿斯Y, and CSV engines are mandatory (always
compiled into the server) and need not be installed
explicitly.(表达:mysql暗中认可帮忙的数据库引擎有MyISAM, ME本田UR-VGE, MEMO哈弗Y,
CSV,无需在编写翻译时再证明)
所以地方的编写翻译条件省掉了如下两行
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
但INNODB一定要表明式安装,所以多了那一行
-DWITH_INNOBASE_STORAGE_ENGINE=1 \

翻看mysql.mysql的用户及组是不是存在

[[email protected]
~]# cat /etc/passwd |grep mysql

mysql:x:501:503::/home/mysql:/bin/bash

[[email protected]
~]# cat /etc/group |grep mysql

mysql:x:503:

不OK就实践以下两行命令(不然跳过这一步)
[[email protected]
~]# groupadd mysql #添加mysql用户组
[[email protected]
~]# useradd mysql -g mysql -s /sbin/nologin # 添加mysql用户

以下带天灰字体的通令分外尤其,必须求举办
[[email protected]
~]# cd /usr/local/mysql
[[email protected]
~]# chown mysql.mysql -R . #将mysql目录赋予mysql用户的进行权限
[[email protected]
~]# chown mysql.mysql -R /data/mysql
[[email protected]
~]# cp support-files/my-default.cnf /etc/my.cnf #mysql配置文件
[[email protected]
~]# chmod 755 scripts/mysql_install_db
#赋予mysql_install_db实施权限

以下命令为mysql 运转及自运行配置
[[email protected]
~]# scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql
–datadir=/data/mysql/

输出如下消息:

2013-12-12 13:58:23 25913 [Note] InnoDB: The InnoDB memory heap is
disabled

2013-12-12 13:58:23 25913 [Note] InnoDB: Mutexes and rw_locks use GCC
atomic builtins

2013-12-12 13:58:23 25913 [Note] InnoDB: Compressed tables use zlib
1.2.3

2013-12-12 13:58:23 25913 [Note] InnoDB: Using Linux native AIO

2013-12-12 13:58:23 25913 [Note] InnoDB: Not using CPU crc32
instructions

2013-12-12 13:58:23 25913 [Note] InnoDB: Initializing buffer pool,
size = 128.0M

2013-12-12 13:58:23 25913 [Note] InnoDB: Completed initialization of
buffer pool

2013-12-12 13:58:23 25913 [Note] InnoDB: The first specified data file
./ibdata1 did not exist: a new database to be created!

2013-12-12 13:58:23 25913 [Note] InnoDB: Setting file ./ibdata1 size
to 12 MB

2013-12-12 13:58:23 25913 [Note] InnoDB: Database physically writes
the file full: wait…

2013-12-12 13:58:23 25913 [Note] InnoDB: Setting log file
./ib_logfile101 size to 48 MB

2013-12-12 13:58:24 25913 [Note] InnoDB: Setting log file
./ib_logfile1 size to 48 MB

2013-12-12 13:58:24 25913 [Note] InnoDB: Renaming log file
./ib_logfile101 to ./ib_logfile0

2013-12-12 13:58:24 25913 [Warning] InnoDB: New log files created,
LSN=45781

2013-12-12 13:58:24 25913 [Note] InnoDB: Doublewrite buffer not found:
creating new

2013-12-12 13:58:24 25913 [Note] InnoDB: Doublewrite buffer created

2013-12-12 13:58:24 25913 [Note] InnoDB: 128 rollback segment(s) are
active.

2013-12-12 13:58:24 25913 [Warning] InnoDB: Creating foreign key
constraint system tables.

2013-12-12 13:58:24 25913 [Note] InnoDB: Foreign key constraint system
tables created

2013-12-12 13:58:24 25913 [Note] InnoDB: Creating tablespace and
datafile system tables.

2013-12-12 13:58:24 25913 [Note] InnoDB: Tablespace and datafile
system tables created.

2013-12-12 13:58:24 25913 [Note] InnoDB: Waiting for purge to start

2013-12-12 13:58:24 25913 [Note] InnoDB: 5.6.15 started; log sequence
number 0

2013-12-12 13:58:26 25913 [Note] Binlog end

2013-12-12 13:58:26 25913 [Note] InnoDB: FTS optimize thread exiting.

2013-12-12 13:58:26 25913 [Note] InnoDB: Starting shutdown…

2013-12-12 13:58:27 25913 [Note] InnoDB: Shutdown completed; log
sequence number 1625977

OK

 

Filling help tables…2013-12-12 13:58:27 0 [Warning] TIMESTAMP with
implicit DEFAULT value is deprecated. Please use
–explicit_defaults_for_timestamp server option (see documentation
for more details).

2013-12-12 13:58:27 25936 [Note] InnoDB: The InnoDB memory heap is
disabled

2013-12-12 13:58:27 25936 [Note] InnoDB: Mutexes and rw_locks use GCC
atomic builtins

2013-12-12 13:58:27 25936 [Note] InnoDB: Compressed tables use zlib
1.2.3

2013-12-12 13:58:27 25936 [Note] InnoDB: Using Linux native AIO

2013-12-12 13:58:27 25936 [Note] InnoDB: Not using CPU crc32
instructions

2013-12-12 13:58:27 25936 [Note] InnoDB: Initializing buffer pool,
size = 128.0M

2013-12-12 13:58:27 25936 [Note] InnoDB: Completed initialization of
buffer pool

2013-12-12 13:58:27 25936 [Note] InnoDB: Highest supported file format
is Barracuda.

2013-12-12 13:58:27 25936 [Note] InnoDB: 128 rollback segment(s) are
active.

2013-12-12 13:58:27 25936 [Note] InnoDB: Waiting for purge to start

2013-12-12 13:58:27 25936 [Note] InnoDB: 5.6.15 started; log sequence
number 1625977

2013-12-12 13:58:27 25936 [Note] Binlog end

2013-12-12 13:58:27 25936 [Note] InnoDB: FTS optimize thread exiting.

2013-12-12 13:58:27 25936 [Note] InnoDB: Starting shutdown…

2013-12-12 13:58:29 25936 [Note] InnoDB: Shutdown completed; log
sequence number 1625987

OK

 

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

 

/usr/local/mysql/bin/mysqladmin -u root password ‘new-password’

/usr/local/mysql/bin/mysqladmin -u root -h ziteng26 password
‘new-password’

 

Alternatively you can run:

 

/usr/local/mysql/bin/mysql_secure_installation

 

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

 

cd . ; /usr/local/mysql/bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

 

cd mysql-test ; perl mysql-test-run.pl

 

Please report any problems with the ./bin/mysqlbug script!

 

The latest information about MySQL is available on the web at

 

http://www.mysql.com

 

Support MySQL by buying support/licenses at http://shop.mysql.com

 

New default config file was created as /usr/local/mysql/my.cnf and

will be used by default by the server when you start it.

You may edit this file to change server settings

 

WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

 

–defaults-file argument to mysqld_safe when starting the server

 

[[email protected]
~]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected]
~]# chmod 755 /etc/init.d/mysqld
查看mysqld服务是还是不是设置为开机运行
[[email protected]
~]# chkconfig –list|grep mysqld
安装为开机运维
[[email protected]
~]# chkconfig mysqld on

开发银行mysql数据库,会输出1雨后玉兰片立竿见影的新闻,告诉你接下去怎样起首化mysql

[[email protected]
mysql]# service mysqld start

依照上述英文,我们来伊始化助理馆员root的密码

[[email protected]
~]# /usr/local/mysql/bin/mysqladmin -u root password ‘yourpassword’

此处yourpassword设置为 manager

 

 

精晓,mysql有二种帐号类型,即localhost和%,前者限本机连接mysql,后者可用于任何机器远程连接mysql

提及底,管理帐号登入难点,让root帐号密码能够本地和长距离连接使用

[[email protected]
~]# /usr/local/mysql/bin/mysql -u root -p
#敲入该命令后,荧屏会提醒输入密码,输入上一步设置的yourpassword

删除root密码为空的记录

mysql> use mysql;

mysql> delete from user where password=”;

mysql> flush privileges;

铺排mysql允许root远程登入 #登录

mysql> grant all privileges on *.* to
[email protected]‘%’
identified by “manager”;

mysql> flush privileges;

mysql> select User,Password,Host from user;

 

上述命令借使进行成功

 

mysql> quit

 

 

现今,mysql安装已经全副结束.

 

http://www.bkjia.com/Mysql/1023547.htmlwww.bkjia.comtruehttp://www.bkjia.com/Mysql/1023547.htmlTechArticleCentos6源码部署MySQL5.6
mysql从伍.5本子早先,不再使用./configure编写翻译,而是选拔cmake编写翻译器
mysql-5.陆.1陆.tar.gz源码包下载地址: http://dev.mysql.com/ge

2、MySQL的设置方式:

以下是MySQL常见的三种安装格局:

  • 二进制  rpm   Yum Repository   
    mysql57-community-release-el7-9.noarch.rpm
  • 二进制  预编译  Generic                       
    mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
  • 源码包安             Source Code              
     
    mysql-5.7.19.tar.gz

叁、Yum的形式安装MySQL:

一、下载安装包

二、 设置安装起来情形

暂时先把防火墙关闭保证实验顺利:
[root@host-131 ~]# systemctl stop firewalld 
[root@host-131 ~]# systemctl disable firewalld.service
临时关闭SELlinux:
[root@host-131 ~]# setenforce 0
永久关闭SELinux:
[root@host-131 ~]# sed -ri '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
查看SELinux状态:
[root@host-131 ~]# getenforce
Disabled

 三、卸载系统自带的数据库(Centos七自带的是maridb)

可参考:【MySQL解惑笔记】Centos7下卸载通透到底MySQL数据库

卸载maridb:
[root@host-131 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@host-131 ~]# yum -y remove mari*
[root@host-131 ~]# rm -rf /var/lib/mysql/*
[root@host-131 ~]# rpm -qa | grep mariadb
[root@host-131 ~]# 

4、修改货仓

[root@host-131 src]# yum rpolist all |grep mysql      //查看所有仓库,并能够看到开启和禁用的仓库
[root@host-131 src]# yum repolist enabled | grep "mysql.*-community.*"  //查看所有开启的仓库,发现现在开启的是MySQL 8.0的,我们需要开启MySQL5.7的仓库
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql80-community/x86_64          MySQL 8.0 Community Server                  17     //k

 开启和关闭不同仓库,官方提供了三种修改方法:

方法一:
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community

方法二:
shell> sudo dnf config-manager --disable mysql57-community
shell> sudo dnf config-manager --enable mysql56-community

方法三:
我们直接修改Yum源文件:
[root@host-131 ~]# cd /etc/yum.repos.d 
[root@host-131 yum.repos.d]# vim mysql-community.repo 
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1                        //修改为1表示开启
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0                        //修改为0表示关闭
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[root@host-131 yum.repos.d]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql57-community/x86_64          MySQL 5.7 Community Server                 267    //可以看到5.7存储仓库已经开启

注意:我们应该在任何时候只启用一个发布系列的子存储库。当启用多个发布系列的子存储库时,Yum将使用最新的系列。
通过运行以下命令并检查其输出(对于Fedora,用dnf替换yum),验证是否启用了正确的子库并禁用了它:
[root@host-131 yum.repos.d]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql57-community/x86_64          MySQL 5.7 Community Server                 267

 5、安装MySQL数据库

[root@host-131 yum.repos.d]# yum -y install mysql-community-server
[root@host-131 ~]# systemctl start mysqld   
[root@host-131 ~]# systemctl enable mysqld   设置开机自启动
[root@host-131 ~]# systemctl status mysqld  查看mysql启动状态

[root@host-131 ~]# ls /var/lib/mysql    (安装后可以看到初始化的数据库)
auto.cnf    client-cert.pem  ibdata1      ibtmp1      mysql.sock.lock     public_key.pem   sys
ca-key.pem  client-key.pem   ib_logfile0  mysql   performance_schema  server-cert.pem
ca.pem      ib_buffer_pool   ib_logfile1  mysql.sock  private_key.pem     server-key.pem

6、第一回登入数据库,并设置初步化密码

[root@host-131 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
发现是禁止访问的

在服务器的初始启动时,由于服务器的数据目录为空:服务器初始化。SSL证书和密钥文件是在数据目录中生成的。
安装并启用了validate_password。
一个超级用户帐户'root'@'localhost被创建。
超级用户的密码被设置并存储在错误日志文件中。要显示它,请使用以下命令:

MySQL5.5之前版本安装后可以直接登录
MySQL5.5自动生成的密码是空的
MySQL5.6是将密码放在root下的
MySQL5.7是将密码放在:
[root@host-131 ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-30T06:34:56.956716Z 1 [Note] A temporary password is generated for root@localhost: xt8S3rWXOL/C
[root@host-131 ~]# 
[root@host-131 ~]# mysql -uroot -p"xt8S3rWXOL/C"
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.22
修改密码:
方法一:
[root@host-131 ~]# mysqladmin -uroot -p"xt8S3rWXOL/C" password "Yanglt123."   //密码要满足复杂性要求
[root@host-131 ~]# mysql -uroot -p"Yanglt123."

方法二:

[root@host-131 ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-30T06:34:56.956716Z 1 [Note] A temporary password is generated for root@localhost: xt8S3rWXOL/C
[root@host-131 ~]# 
[root@host-131 ~]# mysql -uroot -p"xt8S3rWXOL/C"

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

 到此数据库安装成功:

源码安装可参考小说:*【Linux运营】LNMP意况安顿*

  

留下评论

网站地图xml地图