Linux 下 MySQL 的安装

发布于 2022-12-29 14:36:20 字数 4736 浏览 93 评论 0

  • 本文操作系统: CentOS 7.2.1511 x86_64
  • MySQL 版本: 5.7.13

1、卸载系统自带的 mariadb-lib

[root@centos-linux ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@centos-linux ~]# rpm -e mariadb-libs-5.5.44-2.el7.centos.x86_64 --nodeps

2、下载 rpm 安装包

[root@centos-linux ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar

然后解压

[root@centos-linux ~]# ls
mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar
[root@centos-linux ~]# tar xvf mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar

3、安装

[root@centos-linux ~]# rpm -ivh mysql-community-common-5.7.13-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-libs-5.7.13-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-client-5.7.13-1.el7.x86_64.rpm
[root@centos-linux ~]# rpm -ivh mysql-community-server-5.7.13-1.el7.x86_64.rpm

4、配置 /etc/my.cnf

# For dvice on how to change settings please see
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
#socket=/data/mysql/mysql.sock
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
max_allowed_packet = 128M
group_concat_max_len=10240
ngram_token_size = 4

sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#slow_query_log=1
#slow_query_log_file=/tmp/mysql_slow_querys.log
#long_query_time=3
#log-queries-not-using-indexes
log-slow-admin-statements

query_cache_size = 40M
query_cache_type = ON
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
#datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
#socket=/data/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#[mysqladmin]
#socket=/data/mysql/mysql.sock
#password=root
#[mysqldump]
#socket=/data/mysql/mysql.sock

5、数据库初始化

mysqld --initialize --user=mysql

6、查看系统生成的数据库密码

root@centos-linux ~]# cat /var/log/mysqld.log
2016-07-16T07:56:38.282824Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-07-16T07:56:38.422114Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-07-16T07:56:38.449315Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-07-16T07:56:38.457910Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d3261dbf-4b2a-11e6-86ef-001c4260563f.
2016-07-16T07:56:38.458976Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-07-16T07:56:38.459524Z 1 [Note] A temporary password is generated for root@localhost: hm9dKgzQdm:W

7、修改 root 密码,支持局域网访问

[root@centos-linux ~]# systemctl start mysqld
[root@centos-linux ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.13

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>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
mysql>grant all privileges on *.* to 'root'@'%' identified by 'new_password' with grant option;
mysql>flush privileges;

备份数据

mysqldump -h 10.64.77.160 -u root --password=root xxxxx > xxx20180608.sql
zip xxx20180608.zip xxx20180608.sql

还原

CREATE DATABASE `xxxx` DEFAULT CHARACTER SET utf8  DEFAULT COLLATE utf8_general_ci;
source xxx20180608.sql

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

对风讲故事

暂无简介

文章
评论
28 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文