M-63.第十周作业

1、在阿里云服务器搭建openv-p-n(有条件的同学再做)

2、通过编译、二进制安装MySQL5.7

编译安装

1、源码包下载,官网下载地址:https://downloads.mysql.com/archives/community/,点击下载,还有boost_1_59_0.tar.gz这个源码包也要提前下载好,然后将源码包上传到Linux系统

[root@centos7 ~]#ll

total 131916

-rw-r--r-- 1 root root 51363998 Jan 27 21:58 mysql-boost-5.7.30.tar.gz

-rw-r--r-- 1 root root 83709983 Jan 27 21:58 boost_1_59_0.tar.gz

2、安装相关依赖包

[root@centos7 ~]#yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper

3、创建用户和数据目录

[root@centos7 ~]#useradd -r -s /sbin/nologin -d /data/mysql mysql

[root@centos7 ~]#id mysql

uid=995(mysql) gid=992(mysql) groups=992(mysql)

4、创建数据库目录,修改权限

[root@centos7 ~]#mkdir /data/mysql -pv

mkdir: created directory ‘/data/mysql’

[root@centos7 ~]#chown mysql.mysql /data/mysql/

[root@centos7 ~]#ll -d /data/mysql/

drwxr-xr-x 2 mysql mysql 6 Jan 27 20:42 /data/mysql/

5、解压缩源码包

[root@centos7 ~]#tar xvf mysql-boost-5.7.30.tar.gz -C /usr/local/src

[root@centos7 ~]#tar xvf boost_1_59_0.tar.gz -C /usr/local/src

6、源码编译安装 MySQL

[root@centos7 ~]#cd /usr/local/src/mysql-5.7.30/

[root@centos7 mysql-5.7.30]#pwd

/usr/local/src/mysql-5.7.30

[root@centos7 mysql-5.7.30]#cmake . \

> -DCMAKE_INSTALL_PREFIX=/apps/mysql \

> -DMYSQL_DATADIR=/data/mysql/ \

> -DSYSCONFDIR=/etc/ \

> -DMYSQL_USER=mysql \

> -DWITH_INNOBASE_STORAGE_ENGINE=1 \

> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \

> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

> -DWITH_PARTITION_STORAGE_ENGINE=1 \

> -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \

> -DWITH_DEBUG=0 \

> -DWITH_READLINE=1 \

> -DWITH_SSL=system \

> -DWITH_ZLIB=system \

> -DWITH_LIBWRAP=0 \

> -DENABLED_LOCAL_INFILE=1 \

> -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \

> -DDEFAULT_CHARSET=utf8 \

> -DDEFAULT_COLLATION=utf8_general_ci \

> -DDOWNLOAD_BOOST=1 \

> -DWITH_BOOST=/usr/local/src/boost_1_59_0

[root@centos7 mysql-5.7.30]#make && make install

提示:如果出错,执行rm -f CMakeCache.txt

7、准备环境变量

[root@centos7 mysql-5.7.30]#echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

[root@centos7 mysql-5.7.30]#. /etc/profile.d/mysql.sh

8、修改配置文件

[root@centos7 mysql-5.7.30]#cd /apps/mysql/

[root@centos7 mysql]#pwd

/apps/mysql

[root@centos7 mysql]#vim /etc/my.cnf

[mysqld]

explicit_defaults_for_timestamp=true

datadir=/data/mysql/

basedir=/apps/mysql/bin/mysql/

port=3306

pid-file=/data/mysql/mysql.pid

socket=/data/mysql/mysql.socket

symbolic-links=0

character_set_server=utf8

user=mysql

[mysqld_safe]

log-error=/data/mysql/mysql.log

[client]

port=3306

socket=/data/mysql/mysql.socket

default-character-set=utf8

9、初始化数据库

[root@centos7 mysql]#bin/mysqld --initialize-insecure --datadir=/data/mysql/ --user=mysql

10、准备启动脚本,并启动服务

[root@centos7 mysql]#cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@centos7 mysql]#chkconfig --add mysqld

[root@centos7 mysql]#systemctl start mysqld

[root@centos7 mysql]#ss -ntl

State      Recv-Q Send-Q              Local Address:Port                            Peer Address:Port

LISTEN    0      128                            *:22                                          *:*

LISTEN    0      100                    127.0.0.1:25                                          *:*

LISTEN    0      128                          [::]:22                                      [::]:*

LISTEN    0      100                        [::1]:25                                      [::]:*

LISTEN    0      80                          [::]:3306                                    [::]:*

11、修改密码,设置的密码一定要记好(大写字母、小写字母、数字加标点符号,密码要定期更换)

[root@centos7 mysql]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.30 Source distribution

Copyright (c) 2000, 2020, 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> status

--------------

mysql  Ver 14.14 Distrib 5.7.30, for Linux (x86_64) using  EditLine wrapper

Connection id: 2

Current database:

Current user: root@localhost

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.7.30 Source distribution

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: utf8

Db    characterset: utf8

Client characterset: utf8

Conn.  characterset: utf8

UNIX socket: /data/mysql/mysql.socket

Uptime: 15 min 17 sec

Threads: 1  Questions: 5  Slow queries: 0  Opens: 105  Flush tables: 1  Open tables: 98  Queries per second avg: 0.005

--------------

mysql> alter user root@'localhost' identified by 'MySQL@2022.';

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye

二进制安装

1、安装相关包

yum -y install libaio numactl-libs

2、创建用户和组

groupadd mysql

useradd -r -g mysql -s /bin/false mysql

3、准备程序文件

wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31-linuxglibc2.12-x86_64.tar.gz

tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local

cd /usr/local/

ln -s mysql-5.7.31-linux-glibc2.12-x86_64/ mysql

chown -R root.root /usr/local/mysql/

4、准备环境变量

echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

. /etc/profile.d/mysql.sh

5、准备配置文件

cp /etc/my.cnf{,.bak}

vim /etc/my.cnf

[mysqld]

datadir=/data/mysql

skip_name_resolve=1

socket=/data/mysql/mysql.sock

log-error=/data/mysql/mysql.log

pid-file=/data/mysql/mysql.pid

[client]

socket=/data/mysql/mysql.sock

6、初始化数据库文件并提取root密码,生成 root 空密码

mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

7、准备服务脚本和启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

chkconfig --add mysqld

service mysqld start

8、修改口令

#修改前面生成的空密码为指定密码(密码要定期修改)

mysqladmin -uroot password MySQL@2022.

9、测试登录

mysql -uroot -pMySQL@2022.


3、二进制安装mariadb10.4

一、下载

[root@localhost src]#wget http://mirrors.dotsrc.org/mariadb//mariadb-10.4.13/bintar-linux-x86_64/mariadb-10.4.13-linux-x86_64.tar.gz

[root@localhost src]# tar -zxvf mariadb-10.4.13-linux-x86_64.tar.gz

[root@localhost src]# mv mariadb-10.4.13-linux-x86_64 /usr/local/mariadb

[root@localhost mariadb]# ls

bin      CREDITS  docs              include        lib  mysql-test  README-wsrep  share      support-files

COPYING  data    EXCEPTIONS-CLIENT  INSTALL-BINARY  man  README.md  scripts      sql-bench  THIRDPARTY

二、配置

新建组及用户

[root@localhost mariadb]# groupadd mysql

[root@localhost mariadb]# useradd -s /sbin/nologin -r -g mysql mysql

配置服务

[root@localhost mariadb]# cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost mariadb]# chmod +x /etc/init.d/mysqld

新建数据目录与权限

[root@localhost mariadb]# mkdir -p /data/mariadb/

[root@localhost mariadb]# chown -R mysql. /data/mariadb

[root@localhost mariadb]# chown -R mysql:mysql /usr/local/mariadb/

配置my.cnf

[root@localhost mariadb]# vim my.cnf

[mysqld]

basedir=/usr/local/mariadb/

datadir=/data/mariadb/

port=3306

pid-file=/data/mariadb/mysql.pid

socket=/tmp/mysql.sock

[mysqld_safe]

log-error=/data/mariadb/mysql.log

[client]

port=3306

socket=/tmp/mysql.sock

default-character-set=utf8

三、数据库初始化

/usr/local/mariadb/scripts/mysql_install_db --defaults-file=/usr/local/mariadb/my.cnf --user=mysql --datadir=/data/mariadb/ --basedir=/usr/local/mariadb/

[root@localhost ~]# /usr/local/mariadb/scripts/mysql_install_db --defaults-file=/usr/local/mariadb/my.cnf --user=mysql --datadir=/data/mariadb/ --basedir=/usr/local/mariadb/

Installing MariaDB/MySQL system tables in '/data/mariadb/' ...

OK

To start mysqld at boot time you have to copy

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

Two all-privilege accounts were created.

One is root@localhost, it has no password, but you need to

be system 'root' user to connect. Use, for example, sudo mysql

The second is mysql@localhost, it has no password either, but

you need to be the system 'mysql' user to connect.

After connecting you can set the password, if you would need to be

able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at http://mariadb.com/kb or the

MySQL manual for more instructions.

You can start the MariaDB daemon with:

cd '/usr/local/mariadb/' ; /usr/local/mariadb//bin/mysqld_safe --datadir='/data/mariadb/'

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

cd '/usr/local/mariadb//mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.

You can find additional information about the MySQL part at:

http://dev.mysql.com

Consider joining MariaDB's strong and vibrant community:

https://mariadb.org/get-involved/

[root@localhost ~]# echo $?

0

四、base目录权限切回root

[root@localhost mariadb]# chown -R root:root /usr/local/mariadb/

五、配置环境变量

配置环境变量

[root@localhost ~]#echo "PATH=/usr/local/mariadb/bin:$PATH" >/etc/profile.d/mariadb.sh

[root@localhost ~]#chmod +x /etc/profile.d/mariadb.sh

[root@localhost ~]#source /etc/profile.d/mariadb.sh

六、启动与登录

[root@localhost ~]# /etc/init.d/mysqld start

Starting mysqld (via systemctl):     

[root@localhost ~]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

报错,

[root@localhost ~]# ps -ef|grep mysql

root      4386  3375  0 13:54 pts/0    00:00:00 grep --color=auto mysql

解决方法:

1、rm -rf /data/mariadb/* 数据目录

[root@localhost ~]# rm -rf /data/mariadb/*

2、重新初始化 ,这里加上–defaults-file=/usr/local/mariadb/my.cnf

[root@localhost ~]# /usr/local/mariadb/scripts/mysql_install_db --defaults-file=/usr/local/mariadb/my.cnf --user=mysql --datadir=/data/mariadb/ --basedir=/usr/local/mariadb/    内容省略

3、换安全模式启动,登录改root密码

mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf &

[root@localhost ~]# mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf &

[1] 4692

[root@localhost ~]# 200605 14:00:41 mysqld_safe Logging to '/data/mariadb/mysql.log'.

200605 14:00:41 mysqld_safe Starting mysqld daemon with databases from /data/mariadb/

[root@localhost ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 8

Server version: 10.4.13-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test              |

+--------------------+

4 rows in set (0.002 sec)

MariaDB [(none)]> use mysql

MariaDB [mysql]> alter user 'root'@'localhost' identified by '123456';

Query OK, 0 rows affected (0.002 sec)

MariaDB [mysql]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.001 sec)

4、配置安全模式

[root@localhost ~]# mysql_secure_installation --basedir=/usr/local/mariadb/

print: /usr/local/mariadb//bin/my_print_defaults

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current

password for the root user. If you've just installed MariaDB, and

haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody

can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y

Enabled successfully!

Reloading privilege tables..

... Success!

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n

... skipping.

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y

... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

5、重启服务,再mysql登录

[root@localhost ~]# /etc/init.d/mysqld stop

[root@localhost ~]# /etc/init.d/mysqld start

Starting mysqld (via systemctl):                          [  OK  ]

[root@localhost ~]# ps -ef|grep mysql

root      7104    1  0 14:27 ?        00:00:00 /bin/sh /usr/local/mariadb//bin/mysqld_safe --datadir=/data/mariadb/ --pid-file=/data/mariadb/mysql.pid

mysql    7219  7104  4 14:27 ?        00:00:00 /usr/local/mariadb/bin/mysqld --basedir=/usr/local/mariadb/ --datadir=/data/mariadb/ --plugin-dir=/usr/local/mariadb//lib/plugin --user=mysql --log-error=/data/mariadb/mysql.log --pid-file=/data/mariadb/mysql.pid --socket=/tmp/mysql.sock --port=3306

root      7257  3375  0 14:27 pts/0    00:00:00 grep --color=auto mysql

[root@localhost ~]#

[root@localhost ~]# mysql  这里可以正常登录了

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 9

Server version: 10.4.13-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

3 rows in set (0.001 sec)

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,752评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,100评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,244评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,099评论 1 286
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,210评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,307评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,346评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,133评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,546评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,849评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,019评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,702评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,331评论 3 319
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,030评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,260评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,871评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,898评论 2 351

推荐阅读更多精彩内容

  • 1、简述DNS服务器原理,并搭建主-辅服务器。 DNS服务器原理:DNS是分布式的,将其网上的域名和IP地址相互映...
    Gustav_man阅读 542评论 0 0
  • 一、编译安装LNMP,并安装wordpress 主机: 一台(192.168.17.7),系统为CentOS7.6...
    Gustav_man阅读 160评论 0 0
  • 1、搭建mogilefs MogileFS是一个开源的分布式文件存储系统,由LiveJournal旗下的Danga...
    stephe_c阅读 1,122评论 0 1
  • 第十周 1、在阿里云服务器搭建openv-p-n(有条件的同学再做) 搭建失败,用的腾讯云。配置都核对过(不然报错...
    如是我闻_17e6阅读 222评论 0 0
  • centos7.4下源码安装mariadb 一、卸载旧的mariadb 查询已安装的软件: rpm -qa | g...
    Anwar_ec28阅读 1,359评论 0 0