linux mysql 8.0.14_Linux安装MySQL8.0

环境

Centos 7

MySQL 8

下载安装

1.进入MySQL官网选择对应版本下载

54ab722ced277466b7e93fb185ff328f.png

2.使用scp将下载的MySQL压缩文件上传到Linux

scp mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz root@192.168.1.1:mysql

scp: 上传命令

mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz : 上传的文件

root@192.168.1.1:Linux的账号和密码

mysql:Linux接收的目录,在~目录下

3.登录Linux,解压文件

通过ssh远程登录Linux

ssh root@192.168.1.1

进入~目录,解压

tar Jxvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

4.将解压后的文件移动到/usr/local/mysql

/usr/local目录是用来存放本地资源,一般安装在这里

mv mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz /usr/local/mysql

5.配置mysql

mysql配置文件是/etc下的my.cnf

打开文件

vim /etc/my.cnf

将该配置拷贝进文件

[client]

port = 3306

socket = /usr/local/mysql/data/mysql.sock

[mysqld]

# Skip #

skip_name_resolve = 1

skip_external_locking = 1

skip_symbolic_links = 1

# GENERAL #

user = mysql

default_storage_engine = InnoDB

# 字符集,默认是utf8mb4

character-set-server = utf8

socket = /usr/local/mysql/data/mysql.sock

pid_file = /usr/local/mysql/data/mysqld.pid

basedir = /usr/local/mysql

port = 3306

bind-address = 0.0.0.0

explicit_defaults_for_timestamp = off

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#read_only=on

# MyISAM #

key_buffer_size = 32M

#myisam_recover = FORCE,BACKUP

# undo log #

innodb_undo_directory = /usr/local/mysql/undo

innodb_undo_tablespaces = 8

# SAFETY #

max_allowed_packet = 100M

max_connect_errors = 1000000

sysdate_is_now = 1

#innodb = FORCE

#innodb_strict_mode = 1

secure-file-priv='/tmp'

default_authentication_plugin='mysql_native_password'

# Replice #

server-id = 1001

relay_log = mysqld-relay-bin

gtid_mode = on

enforce-gtid-consistency

log-slave-updates = on

master_info_repository =TABLE

relay_log_info_repository =TABLE

# DATA STORAGE #

datadir = /usr/local/mysql/data/

tmpdir = /tmp

# BINARY LOGGING #

log_bin = /usr/local/mysql/sql_log/mysql-bin

max_binlog_size = 1000M

binlog_format = row

binlog_expire_logs_seconds=86400

# sync_binlog = 1

# CACHES AND LIMITS #

tmp_table_size = 32M

max_heap_table_size = 32M

max_connections = 4000

thread_cache_size = 2048

open_files_limit = 65535

table_definition_cache = 4096

table_open_cache = 4096

sort_buffer_size = 2M

read_buffer_size = 2M

read_rnd_buffer_size = 2M

# thread_concurrency = 24

join_buffer_size = 1M

# table_cache = 32768

thread_stack = 512k

max_length_for_sort_data = 16k

# INNODB #

innodb_flush_method = O_DIRECT

innodb_log_buffer_size = 16M

innodb_flush_log_at_trx_commit = 2

innodb_file_per_table = 1

innodb_buffer_pool_size = 256M

#innodb_buffer_pool_instances = 8

innodb_stats_on_metadata = off

innodb_open_files = 8192

innodb_read_io_threads = 16

innodb_write_io_threads = 16

innodb_io_capacity = 20000

innodb_thread_concurrency = 0

innodb_lock_wait_timeout = 60

innodb_old_blocks_time=1000

innodb_use_native_aio = 1

innodb_purge_threads=1

innodb_change_buffering=all

innodb_log_file_size = 64M

innodb_log_files_in_group = 2

innodb_data_file_path = ibdata1:256M:autoextend

innodb_rollback_on_timeout=on

# LOGGING #

log_error = /usr/local/mysql/sql_log/mysql-error.log

# log_queries_not_using_indexes = 1

# slow_query_log = 1

slow_query_log_file = /usr/local/mysql/sql_log/slowlog.log

# TimeOut #

#interactive_timeout = 30

#wait_timeout = 30

#net_read_timeout = 60

[mysqldump]

quick

max_allowed_packet = 100M

[mysql]

no-auto-rehash

# Remove the next comment character if you are not familiar with SQL

#safe-updates

[myisamchk]

key_buffer_size = 256M

sort_buffer_size = 256M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

6.创建配置文件用到的目录

进入mysql目录

cd /usr/local/mysql

创建目录

mkdir data sql_log undo

7.创建mysql用户

因为要用到mysql用户来启动mysql

adduser mysql

8.赋予mysql用户读写文件的权限

chown mysql:mysql -R data sql_log undo

chmod -R 777 data sql_log undo

9.配置MySQL环境变量

打开环境变量配置文件

vim /etc/profile

在文件末尾添加MySQL环境变量

export PATH=$PATH:/usr/local/mysql/bin

10.初始化MySQL

1.进入mysql目录

cd /usr/local/mysql

2.进行初始化

—user=mysql:初始化用户

--basedir=/usr/local/mysql:MySQL目录

--datadir=/usr/local/mysql/data:MySQL数据存放目录

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

3.进入data目录,查看是否有文件

有文件就是启动成功

cd data

11.预备启动MySQL

进入mysql目录

cd /usr/local/mysql

将support-files/mysql.server拷贝到/etc/init.d/mysqld

support-files/mysql.server:mysql启动脚本

/etc/init.d/:用来存放服务脚本,可以通过service xxx start来启动

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

12.启动、停止、重启MySQL

service mysqld start|stop|restart

或者

/etc/init.d/mysqld start|stop|restart

13.测试是否启动成功

ps -ef|grep mysqld

14.查看MySQL初始化密码

记录在sql_log的mysql_error.log中

进入sql_log目录

cd sql_log

查看mysql-error.log文件

grep password mysql-error.log

如果密码不在文件里,需要修改初始化密码

1.打开MySQL配置文件

vi /etc/my.cnf

2.添加跳过登录验证功能

在文件里添加这句即可

skip-grant-tables

3.wq保存退出

4.连接mysql

mysql

5.刷新权限表

flush privileges;

6.修改密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

7.退出exit,即修改成功

15.连接MySQL

mysql -uroot -p [-h]

-u : 用户

-p : 密码

-h : MySQL的ip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值