文章目录
参考链接:https://blog.csdn.net/atongmu2017/article/details/90610444
检查并卸载
rpm -qa|grep -i mysql
打印结果
mysql-community-libs-8.0.18-1.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-common-8.0.18-1.el7.x86_64
mysql-community-libs-compat-8.0.18-1.el7.x86_64
mysql-community-client-8.0.18-1.el7.x86_64
卸载
yum remove mysql-community-libs-8.0.18-1.el7.x86_64
yum remove mysql80-community-release-el7-3.noarch
yum remove mysql-community-common-8.0.18-1.el7.x86_64
yum remove mysql-community-libs-compat-8.0.18-1.el7.x86_64
yum remove mysql-community-client-8.0.18-1.el7.x86_64
下载和安装
- 下载地址 https://dev.mysql.com/downloads/repo/yum/
- 下载 mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
解压
tar xvJf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
# 重新命名
mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql
# 移动
mv mysql /usr/local
进入到/usr/local目录下,创建用户和用户组并授权
cd /usr/local
groupadd mysql
useradd -r -g mysql mysql
#注意:进入mysql文件下授权所有的文件
cd mysql
chown -R mysql:mysql ./
#修改mysql用户密码
passwd mysql
创建data文件夹
pwd
# /usr/local/myql
mkdir data
初始化数据库,并会自动生成随机密码,记下等下登陆要用
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# for root@localhost: oVeyi8*SM*.W
修改/usr/local/mysql当前目录的用户
chown -R root:root ./
chown -R mysql:mysql data
# 查看结果
ll
打印出的结果为:
drwxr-xr-x. 2 root root 4096 9月 20 20:57 bin
drwxr-xr-x. 6 mysql mysql 4096 11月 3 21:30 data
drwxr-xr-x. 2 root root 86 9月 20 20:57 docs
drwxr-xr-x. 3 root root 4096 9月 20 20:57 include
drwxr-xr-x. 7 root root 4096 9月 20 20:57 lib
-rwxr-xr-x. 1 root root 408918 9月 20 16:30 LICENSE
-rwxr-xr-x. 1 root root 102977 9月 20 16:30 LICENSE.router
drwxr-xr-x. 4 root root 30 9月 20 20:57 man
-rwxr-xr-x. 1 root root 687 9月 20 16:30 README
-rwxr-xr-x. 1 root root 700 9月 20 16:30 README.router
drwxr-xr-x. 2 root root 6 9月 20 20:57 run
drwxr-xr-x. 28 root root 4096 9月 20 20:57 share
drwxr-xr-x. 2 root root 108 11月 3 20:37 support-files
drwxr-xr-x. 3 root root 17 9月 20 20:57 var
编辑 etc/my.cnf 文件
# 在目录support-files下
pwd
cd support-files
#新建文件
touch my-default.cnf
#赋权
chmod 777 ./my-default.cnf
#复制
cp my-default.cnf /etc/my.cnf
#编辑/etc/my.cnf文件
vim /etc/my.cnf
/etc/my.cnf 文件内容如下【端口号可自己设置本例为5186】
[mysqld]
# 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
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
port = 5186
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
开机自启,进入/usr/local/mysql/support-files进行设置
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
注册服务
chkconfig --add mysql
etc/ld.so.conf要配置路径
vim /etc/ld.so.conf
添加如下内容
/usr/local/mysql/lib
配置环境变量
vim /etc/profile
增加如下内容
#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
增加后使文件生效
source /etc/profile
启动mysql
#启动命令
systemctl start mysql
#查看状态
systemctl status mysql
# 停服务
systemctl stop mysql
Mysql 查看端口号的几种方式
1.ps
ps -ef|grep mysql|grep port
#或者
ps aux|grep mysql|grep port
2.netstat用于显示各种网络相关信息
netstat -antp|grep mysql|grep LISTEN
3.察看/etc/my.cnf 文件
grep port /etc/my.cnf
登录sql
mysql -u root -p
#密码为之前生成的随机密码
进入mysql之后修改登录密码
alter user 'root'@'localhost' identified by '123456';
远程连接
create user 'cici'@'%' identified by '123123';
grant all on *.* to 'cici'@'%';
flush privileges;
远程连接账户 cici 密码 123123
注意如果连不上,需要检查一下防火墙