赞
踩
一、压缩包下载
压缩包下载路径:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
二、安装
2.1、解压缩
tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
2.2、创建安装目录
mkdir /usr/local/mysql
将解压后的文件夹拷贝至安装目录/usr/lcoal/mysql/,并重命名为mysql-5.7
mv mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql/mysql-5.7
2.3、创建相关目录
- mkdir /usr/local/mysql/mysql-5.7/data
- mkdir /usr/local/mysql/mysql-5.7/log
- touch /usr/local/mysql/mysql-5.7/log/mysqld.log
2.4、创建linux用户
- su root
- groupadd mysql #添加mysql组
- useradd -r -g mysql mysql #添加mysql用户
2.5、更改文件归属
- chown -R mysql /usr/local/mysql/mysql-5.7
- chgrp -R mysql /usr/local/mysql/mysql-5.7
2.6、初始化MySQL
- cd /usr/local/mysql/mysql-5.7
-
- bin/mysqld --user=mysql --basedir=/usr/local/mysql/mysql-5.7/ --datadir=/usr/local/mysql/mysql-5.7/data --initialize
输出如下信息,会生成一个临时登录密码
root@ubuntu:/usr/local/mysql/mysql-5.7# bin/mysqld --user=mysql --basedir=/usr/local/mysql/mysql-5.7/ --datadir=/usr/local/mysql/mysql-5.7/data --initialize
2022-04-16T10:18:43.242411Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-04-16T10:18:43.417483Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-04-16T10:18:43.452197Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-04-16T10:18:43.512300Z 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: 97f52ec0-bd6e-11ec-a319-000c29bea374.
2022-04-16T10:18:43.515493Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-04-16T10:18:44.181127Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-04-16T10:18:44.181190Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-04-16T10:18:44.181612Z 0 [Warning] CA certificate ca.pem is self signed.
2022-04-16T10:18:44.270207Z 1 [Note] A temporary password is generated for root@localhost: -62P&d,D8m,%
三、配置MySQL
3.1、修改配置文件
vim /etc/my.cnf
添加如下内容
- [mysqld]
- datadir=/usr/local/mysql/mysql-5.7/data
- basedir=/usr/local/mysql/mysql-5.7
- socket=/tmp/mysqld.sock
- user=mysql
- port=3306
- character-set-server=utf8
- skip-grant-tables
- symbolic-links=0
- [mysqld_safe]
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
-
- [client]
- socket=/tmp/mysqld.sock
-
3.2、启动MySQL
- cd /usr/local/mysql/mysql-5.7/support-files
- sh mysql.server start
查看MySQL服务是否启动成功
- sh support-files/mysql.server status
-
-
- * MySQL running (6787)
-
3.3、配置环境变量
vim /etc/profile
添加如下内容
export PATH=$PATH:/usr/local/mysql/mysql-5.7/bin
使配置生效
source /etc/profile
3.4、允许root账号远程访问
先本地登录mysql,查询权限
- use mysql;
- select User,authentication_string,Host from user;
mysql> select User,authentication_string,Host from user;
+---------------+-------------------------------------------+-----------+
| User | authentication_string | Host |
+---------------+-------------------------------------------+-----------+
| root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
设置权限
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root'
- flush privileges;
3.5、修改登录密码
- set password for root@'%'=password('123456');
- flush privileges;
四、安装过程中的问题及解决办法
4.1、初始化报错
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决办法:
yum install -y libaio.so.1
yum install -y libaio
4.2、修改权限报错
mysql> grant all on cactidb.* to dbuser@'localhost' identified by '123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解决办法:
先输入 flush privileges; 刷新一下权限表,再重新执行grant命令,就成功了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。