Linux(centOS7)上mysql8.0安装教程mysql官⽹下载地址:
第⼀步:压缩⽂件下载、解压(事先创好的⽬录为:/software/Mysql)
进⼊/software/Mysql⽬录
cd /software/Mysql
输⼊以下指令下载mysql压缩包(服务器接⼊互联⽹的情况下执⾏)
wget
解压压缩包
tar -zxvf /software/Mysql/mysql-8.0.21-el7-x86_
第⼆步:移动⽂件mysql-8.0.21-el7-x86_64到/usr/local/mysql8.0⽬录(在根⽬录执⾏)
mv mysql-8.0.21-el7-x86_64 /usr/local/mysql8.0
第三步:进⼊etc⽬录、创建myf⽂件、添加⼀下相应内容
vim /etc/myf
[client]
port = 3306
# 开启socket连接
socket = /tmp/mysql.sock
[mysqld]
skip-name-resolve
# 服务id
server-id = 1
# 登录⽤户
user = mysql
# mysql服务器访问端⼝
port = 3306
# 数据库默认字符集,主流字符集⽀持⼀些特殊表情符号(特殊表情符占⽤4个字节)
character-set-server = utf8mb4
# 数据库字符集对应⼀些排序等规则,注意要和character-set-server对应
collation-server = utf8mb4_general_ci
# mysql安装⽬录
basedir = /usr/local/mysql8.0
# mysql数据库⽂件⽬录
datadir = /usr/local/mysql8.0/data
# 开启socket连接
socket = /tmp/mysql.sock
# mysql进程id所在⽂件
pid-file = /usr/local/mysql8.0/data/mysql.pid
# 开启慢查询
slow_query_log = 1
# 慢查询⽇志⽂件
slow_query_log_file = /usr/local/mysql8.0/logs/mysql-slow.log
# 慢查询执⾏的秒数,必须达到此值可被记录
long_query_time = 10
# mysql错误⽇志
log-error = /usr/local/mysql8.0/logs/mysql.log
# 最⼤连接数
max_connections = 1000
# 连接出错尝试次数
max_connect_errors = 100
# 事务隔离级别,默认为可重复读,mysql默认可重复读级别
transaction_isolation = READ-COMMITTED
# 是否对sql语句⼤⼩写敏感,1表⽰不敏感(默认是0,注意初始化时和下⾯参数的值保持⼀致)
lower_case_table_names = 1
# mysql数据引擎innodb配置(最⼤可以配置到系统内存的80%)
innodb_buffer_pool_size = 256M
flush_time = 0
第四步:创建并配置mysql服务
vim /etc/rc.d/init.d/mysqld
修改⼀下内容:
basedir=/usr/local/mysql8.0
datadir=/usr/local/mysql8.0/data
mysqld_pid_file_path=/usr/local/mysql8.0/data/mysql.pid
第五步:创建⽇志⽂件夹
mkdir /usr/local/mysql8.0/logs
第六步:创建mysql⽤户组和mysql⽤户(mysql出于安全考虑必须创建,删除⽤户和⽤户组userdel mysql)
groupadd mysql
useradd -r -g mysql mysql
第七步:安装⽬录第⼀次授权给mysql⽤户
chown -R mysql:mysql /usr/local/mysql8.0
第⼋步:进⼊根⽬录执⾏mysql初始化命令获取初始密码
/usr/local/mysql8.0/bin/mysqld --user=mysql --lower-case-table-names=1 --initialize
cat /usr/local/mysql8.0/logs/mysql.log | grep password
第九步:安装⽬录、配置⽂件、服务最终授权给mysql⽤户
chown -R mysql:mysql /usr/local/mysql8.0 /etc/myf /etc/rc.d/init.d/mysqld
chmod -R 755 /usr/local/mysql8.0 /etc/myf /etc/rc.d/init.d/mysqld
第⼗步:启动服务修改密码
重新加载系统服务
systemctl daemon-reload
mysql下载安装后怎么用启动mysql服务
systemctl start mysqld.service
/usr/local/mysql8.0/bin/mysql -u root -p
按照提⽰输⼊初始化获取的密码(yourPassword为你⾃⼰的密码)
ALTER USER root@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourPassword';
第⼗⼀步:开启远程访问(在第⼗步的基础上操作)
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
其它服务操作:
查看mysql服务
systemctl status mysqld.service
关闭mysql服务
systemctl stop mysqld.service
重启mysql服务
systemctl restart mysqld.service
删除服务为:
systemctl disable mysqld.service
完整卸载mysql,如果服务已经启动先停⽌服务,删除/usr/local/mysql8.0⽬录和⽂件,删除⽤户和⽤户组mysql,删除myf配置⽂件,删除mysqld服务配置⽂件
rm -rf / usr/local/mysql8.0
userdel mysql
rm -f /etc/myf
rm -f /etc/rc.d/init.d/mysqld
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论