mysql-5.7.23安装包自行下载
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
1.将装备的tar.gz格式的安装包上传到centos8服务器中,进行解压
或者使用wget命令直接下载,但需要可以访问外网
tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
解压完成后,删除压缩包,并将文件夹改名为mysql。
rm -rf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql
创建mysql用户,并更改/usr/local/mysql目录的权限 因为Linux特定的软件要用特定的用户、用户组来运行
useradd -r -s /sbin/nologin mysql
使用 id mysql 查看是否创建成功
id mysql
uid=989(mysql) gid=985(mysql) groups=985(mysql)
使用命令更改文件权限用户,此处的-R起递归作用
chown -R mysql.mysql /usr/local/mysql/
初始化mysql,切换到mysql/bin 目录下。localhost后面的是临时密码,在初次登陆时使用
在装mysql8时:
设置大小写–lower-case-table-names=1不区分大小写的问题上踩了很多坑,也可能不是这种设置方式吧,本身就是一个小白,不会的也去百度,跌跌撞撞,装完之后能用就行了。。。
[root@iZw2fe9o7s1zh3Z bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --initialize --lower-case-table-names=1
2020-07-31T02:18:06.539202Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-31T02:18:07.592266Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-07-31T02:18:07.709475Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-07-31T02:18:07.771767Z 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: 12c05c5c-d2d4-11ea-863f-00163e11e0d0.
2020-07-31T02:18:07.773617Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-07-31T02:18:07.774147Z 1 [Note] A temporary password is generated for root@localhost: pACaa,yu,3xo 这里是随机生成的临时密码,待会首次登陆需要使用
复制suport-files目录下的mysql.server脚本到/etc/init.d目录一份,方便以后使用service命令管理软件
cp suport-files/mysql.server /etc/init.d/mysql
这里将mysql.server文件复制到etc下时,一定要有最后面的mysql,否则在通过service mysql start命令启动时,找不到该命令
启动mysql
service mysql start
# service mysql stop
Starting MySQL.Logging to '/usr/local/mysql/data/iZw2fe9o7s1zh3Z.err'.
[ OK ] OK证明启动成功
登陆,密码默认不显示,正常输入后敲回车即可,此处密码为临时密码。
1 [root@localhost mysql]# bin/mysql -uroot -p
2 Enter password:
登陆进去后,如果不提示修改密码,自己进行修改密码
1 mysql> SET PASSWORD = '这里填写你的密码';
2 Query OK, 0 rows affected (0.02 sec) 出现该字样则修改成功。
授权访问,此处需要创建一个新用户,然后将权限授权给新用户,以后用新用户进行登录(可能会存在不同版本的授权不一样的问题)
1 mysql> CREATE USER '你的用户名字'@'限定的IP地址' IDENTIFIED BY '你的密码'; 限定的IP地址,可以用通配符 % 替换,代表任何IP都可以。
2 Query OK, 0 rows affected (0.02 sec)
3
4 mysql> GRANT ALL ON *.* TO '你的用户名字'@'%';
5 Query OK, 0 rows affected (0.00 sec)
此时,所有操作都做完,你可以在Windows上使用MySQL Workbench进行远程访问服务器上的数据库。
由于从MySQL 5.7.18开始不在二进制包中提供my-default.cnf文件。参考:网址
在后期的使用中发现数据库表名的大小写问题,由于在windows下是不区分大小写的,但到了linux环境下就需要设置是否区分大小写,然后去网上进行百度,说是设置/etc/my.cnf文件,然而在这个etc目录下并没有 发现这个文件,然后再去进行百度,发现了这个,然后在etc目录下新建了my.cnf文件,复制进去了一下内容:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[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
# 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
lower_case_table_names=1
温馨提示:需要什么去复制什么,不要复制太多,再出现其他问题。这里我只想解决不区分大小写,我设置了***lower_case_table_names=1***这个。
搭建参考文章:https://www.cnblogs.com/mohou/p/12444327.html
处理mysql不区分大小写参考文章:https://blog.csdn.net/qq_38545713/article/details/81868846
注:阿里云服务器搭建mysql数据库,需要开放3306端口,否则会出现通过数据库连接工具连接不上的问题。