菜单

【第壹章】MySQL数据库基于Centos7.三-陈设

2019年4月14日 - sqlite

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

Centos六源码安顿MySQL伍.陆

mysql从伍.五版本开首,不再使用./configure编写翻译,而是利用cmake编写翻译器

mysql-伍.6.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 五.6.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官网英文文书档案简约翻译说飞鹤下
The MyISAM, ME福特ExplorerGE, MEMO凯雷德Y, and CSV engines are mandatory (always
compiled into the server) and need not be installed
explicitly.(表达:mysql暗中同意协助的数据库引擎有MyISAM, ME宝马X3GE, MEMO奥迪Q7Y,
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数据库,会输出一名目繁多立见成效的音信,告诉您接下去怎么样起首化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

贰、MySQL的设置格局:

以下是MySQL常见的二种安装方式:

3、Yum的法子安装MySQL:

1、下载安装包

二、 设置安装起来环境

暂时先把防火墙关闭保证实验顺利:
[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

 三、卸载系统自带的数据库(Centos7自带的是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 ~]# 

肆、修改仓库

[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地图