MySql教程

CentOS下安装mysql5.7.36

本文主要是介绍CentOS下安装mysql5.7.36,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、下载地址到国内得开源镜像网站下载
2、解压缩

[root@shigj ~]# ls
mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
[root@shigj ~]# tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.36-linux-glibc2.12-x86_64/bin/myisamlog

3、重命名并移动文件

[root@shigj ~]# mv mysql-5.7.36-linux-glibc2.12-x86_64 /usr/local/mysql

4、创建mysql用户组和用户并修改权限

[root@shigj ~]# groupadd mysql
[root@shigj ~]# useradd -r -g mysql mysql

5、创建数据目录并赋予权限

[root@shigj ~]# mkdir -p  /usr/local/mysql/data      #创建目录
[root@shigj ~]# chown mysql:mysql -R /usr/local/mysql/data  #赋予权限

6、配置my.cnf

[mysqld]
#端口号
port = 3306
#mysql-5.7.36文件的路径
basedir=/usr/local/mysql
#mysql-5.7.36数据路径
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/data/mysql.err
#最大连接数
max_connections=600
#编码
character-set-server=utf8
#skip-grant-tables
default-storage-engine=INNODB
#不区分大小写
lower_case_table_names=1
#绑定ipv4
bind-address=0.0.0.0
#设置传输包限制,默认1M
max_allowed_packet=64M
#设置缓冲池大小:
innodb_buffer_pool_size=1024M
#设置隔离级别
transaction-isolation=read-committed
#设置时区
default-time-zone='+8:00'
#设置密码验证默认加密方式
#default-authentication-plugin=mysql_native_password
explicit_defaults_for_timestamp=true
[mysql]
#编码
default-character-set=utf8

7、初始化数据库
进入mysql的bin目录
出现报错需要安装依赖包

[root@shigj ~]# cd /usr/local/mysql/bin/
[root@shigj bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql --initialize
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@shigj bin]# yum install  libaio-devel.x86_64

7、查看密码

[root@shigj bin]# cat /usr/local/mysql/data/mysql.err
2021-11-10T08:45:20.242160Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-10T08:45:20.288796Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-10T08:45:20.346361Z 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: 895b2959-4202-11ec-8dae-00163e03473d.
2021-11-10T08:45:20.347667Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-10T08:45:21.167981Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-11-10T08:45:21.167993Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-11-10T08:45:21.168567Z 0 [Warning] CA certificate ca.pem is self signed.
2021-11-10T08:45:21.811242Z 1 [Note] A temporary password is generated for root@localhost: egFw0x=%-E/e

8、启动mysql,并更改root 密码
先将mysql.server放置到/etc/init.d/mysql中

[root@shigj bin]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@shigj bin]# /etc/init.d/mysql start
[root@shigj bin]# service mysql restart

配置环境变量

[root@shigj ~]# vi /etc/profile
最后添加export PATH="$PATH:/usr/local/mysql/bin"
[root@shigj ~]# source /etc/profile

修改密码

SET PASSWORD = PASSWORD('one123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;         

修改远程连接

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> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

这篇关于CentOS下安装mysql5.7.36的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!