建站不啰嗦,上手跟我做(六)mysql 数据库下载和安装

下载

mysql 官方下载对应的版本
图片.png

安装

以 mysql-5.7.25-el7-x86_64.tar.gz 为例
第一:解压 mysql 压缩包

[root@localhost opt]# tar -zxvf mysql-5.7.25-el7-x86_64.tar.gz

重命名文件夹名称

[root@localhost opt]# mv mysql-5.7.25-el7-x86_64 mysql

第二:配置

进入到 mysql 目录,可以发现,没有 /data 目录,这里要自己创建一个 data 目录

data 目录并不限定存放位置,但是为了方便,这里依旧直接放在 mysql 的根目录下,

[root@localhost mysql]# mkdir data
[root@localhost mysql]# mkdir log

第三:新建 mysql 的用户和用户组

#添加用户组

[root@localhost mysql]# groupadd mysql

#新建 msyql 用户禁止登录 shell

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

第四:改变 mysql 目录权限

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

第五:修改 mysql 配置

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

[mysqld]

[client]

port = 3306

socket = /opt/mysql/data/mysql.sock

[mysqld]

server_id=10

port = 3306

user = mysql

character-set-server = utf8mb4

default_storage_engine = innodb

log_timestamps = SYSTEM

socket = /opt/mysql/data/mysql.sock

basedir = /opt/mysql

datadir = /opt/mysql/data

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

max_connections = 1000

max_connect_errors = 1000

table_open_cache = 1024

max_allowed_packet = 128M

open_files_limit = 65535

lower_case_table_names=1


#####====================================[innodb]==============================

innodb_buffer_pool_size = 1024M

innodb_file_per_table = 1

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_purge_threads = 2

innodb_flush_log_at_trx_commit = 1

innodb_log_file_size = 512M

innodb_log_files_in_group = 2

innodb_log_buffer_size = 16M

innodb_max_dirty_pages_pct = 80

innodb_lock_wait_timeout = 30

innodb_data_file_path=ibdata1:1024M:autoextend

innodb_undo_tablespaces=3


######====================================[log]==============================

log_error = /opt/mysql/log/mysql-error.log

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /opt/mysql/log/mysql-slow.log

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

第五:初始化数据库

[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp

第六:配置启动文件

[root@localhost mysql]# cd support-files/

[root@localhost support-files]# ls

magic mysqld_multi.server mysql-log-rotate mysql.server

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

[root@localhost support-files]# chkconfig --add mysqld

[root@localhost support-files]# chkconfig mysqld on

[root@localhost support-files]# service mysqld start

Starting MySQL.. SUCCESS!

第七:查看默认密码

[root@localhost log]# cd /opt/mysql/log

[root@localhost log]# more mysql-error.log

2019-02-24T10:59:18.740765+08:00 1 [Note] A temporary password is generated for root@localhost: 8Ukx5oztti=B

ldjL):jf=69F

第八:初始化密码

alias mysql=/opt/mysql/bin/mysql

[root@localhost log]# mysql -uroot -p

Enter password:

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

Your MySQL connection id is 5

Server version: 5.7.25-log

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

mysql> SET PASSWORD=PASSWORD('123456');

Query OK, 0 rows affected, 1 warning (0.00 sec)

修改设置使root账号可以远程访问

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

  

Database changed

mysql> update user set host = '%' where user ='root';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

  

mysql> select host, user from user;

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

| host | user |

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

| % | root |

| localhost | mysql.session |

| localhost | mysql.sys |

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

3 rows in set (0.00 sec)

  

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

修改防火墙设置,3306可以通过防火墙

[root@localhost sysconfig]# systemctl start firewalld

[root@localhost sysconfig]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

[root@localhost sysconfig]# systemctl restart firewalld

重启之后启动mysql服务

[root@localhost log]# service mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL.. SUCCESS!

第九:远程访问
893521D3BE8E48F788EAF61B2A88BF2C.jpg

安装过程中可能出现的问题

问题:
./bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
修复方案:
[root@VM_48_15_centos bin]# yum -y install numactl
问题
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/data/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
修复方案:
[root@localhost mysql]# yum install -y libaio

mysql 服务启动(mysqld 服务无效时)

[root@mysql-master ~]# service mysqld start
mysqld: unrecognized service

[root@mysql-master init.d]# service mysql start
Starting MySQL SUCCESS!

centos 挂载硬盘

mysql 表名是否区分大小写配置
mysql 主主复制配置
上一篇 建站不啰嗦,上手跟我做(五)tomcat 下载和安装
目录
下一篇 建站不啰嗦,上手跟我做(七)oracle 数据库下载和安装