mysql 下载安装及配置

mysql下载安装

查看mysql yum安装包

[ruoyi@vm10-0-0-3 ~]$ yum list mysql*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
MySQL-python.x86_64                                                       1.2.5-1.el7                                                          base
MySQL-zrm.noarch                                                          3.0-17.el7                                                           epel
mysql++.x86_64                                                            3.1.0-12.el7                                                         epel
mysql++-devel.x86_64                                                      3.1.0-12.el7                                                         epel
mysql++-manuals.x86_64                                                    3.1.0-12.el7                                                         epel
mysql-connector-java.noarch                                               1:5.1.25-3.el7                                                       base
mysql-connector-odbc.x86_64                                               5.2.5-8.el7                                                          base
mysql-connector-python.noarch                                             1.1.6-1.el7                                                          epel
mysql-mmm.noarch                                                          2.2.1-15.el7                                                         epel
mysql-mmm-agent.noarch                                                    2.2.1-15.el7                                                         epel
mysql-mmm-monitor.noarch                                                  2.2.1-15.el7                                                         epel
mysql-mmm-tools.noarch                                                    2.2.1-15.el7                                                         epel
mysql-proxy.x86_64                                                        0.8.5-2.el7                                                          epel
mysql-proxy-devel.x86_64                                                  0.8.5-2.el7                                                          epel
mysql-utilities.noarch                                                    1.3.6-1.el7                                                          epel
mysqlreport.noarch                                                        3.5-11.el7                                                           epel
mysqltuner.noarch                                                         1.7.17-2.git.f18a3ef.el7                                             epel

使用yum安装mysql

[root@vm10-0-0-3 ~]# yum install mysql* -y

卸载mysql

[root@vm10-0-0-3 ~]# yum list install mysql*| awk '{print $1}' | xargs rpm -e --nodeps

下载mysql安装包

mysql 下载安装及配置_第1张图片

点击下载,拿到下载连接https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz

[root@vm10-0-0-3 local]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz

解包

[root@vm10-0-0-3 local]# tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz

重命名

[root@vm10-0-0-3 local]# mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql

创建data目录

[root@vm10-0-0-3 mysql]# mkdir data

新建mysql用户及用户组

[root@vm10-0-0-3 mysql]# useradd mysql
[root@vm10-0-0-3 mysql]# passwd mysql

修改目录权限

[root@vm10-0-0-3 local]# chown -R mysql:mysql mysql

编译运行初始化

[root@vm10-0-0-3 bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

执行报错

./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

安装报错类库

[root@vm10-0-0-3 bin]# yum install libaio.so.1
[root@vm10-0-0-3 bin]# yum -y install numactl

重新执行还是同样的报错

[root@vm10-0-0-3 bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

查看安装的版本,默认安装的32位的,但实际应使用64位的

[root@vm10-0-0-3 bin]# yum list libaio*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
libaio.i686                                                              0.3.109-13.el7                                                       @base
Available Packages
libaio.x86_64                                                            0.3.109-13.el7                                                       base 
libaio-devel.i686                                                        0.3.109-13.el7                                                       base 
libaio-devel.x86_64                                                      0.3.109-13.el7                                                       base 
[root@vm10-0-0-3 bin]# yum install libaio.x*


### 再次执行成功
[root@vm10-0-0-3 bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2020-06-16T09:16:13.553039Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-06-16T09:16:13.903569Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-06-16T09:16:13.951441Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-06-16T09:16:14.007676Z 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: 06b96e14-afb2-11ea-b836-fa163e0d9114.
2020-06-16T09:16:14.008595Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-06-16T09:16:14.876493Z 0 [Warning] CA certificate ca.pem is self signed.
2020-06-16T09:16:15.009329Z 1 [Note] A temporary password is generated for root@localhost: HUe9dgUlet&q

启动服务

[root@vm10-0-0-3 ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/vm10-0-0-3.err'.
                                                           [  OK  ]

添加软连接并重启

[root@vm10-0-0-3 ~]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@vm10-0-0-3 ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@vm10-0-0-3 ~]# service mysql restart

登录数据库报错

[root@vm10-0-0-3 ~]#  mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

修改my.cnf文件

[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1
#skip-grant-tables
socket=/usr/local/mysql/data/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid

[client]
port=3306
socket=/usr/local/mysql/data/mysql.sock

[root@vm10-0-0-3 ~]# service mysql restart

重启后再次登录
[root@vm10-0-0-3 ~]#  mysql -u root -p
Enter password: 
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
密码过期问题my.cnf中添加
skip-grant-tables

重启再次登录
[root@vm10-0-0-3 ~]# service mysql restart
[root@vm10-0-0-3 ~]#  mysql -u root -p

设置密码不过期
MySQL [(none)]> 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

MySQL [mysql]> update user set password_expired='N' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MySQL [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MySQL [mysql]> quit

设置可以远程登录

MySQL [mysql]> use mysql;
Database changed
MySQL [mysql]> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MySQL [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

去除my.cnf中新加的
skip-grant-tables

开启云服务器3306端口访问权限

远程访问mysql成功

mysql 下载安装及配置_第2张图片

设置开机启动,拷贝到开机启动目录下

[root@vm10-0-0-3 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
赋予执行权限
[root@vm10-0-0-3 ~]# chmod +x /etc/init.d/mysqld
添加服务检查
[root@vm10-0-0-3 ~]# chkconfig --add mysqld
[root@vm10-0-0-3 ~]# chkconfig --list

错误解决

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysJobServiceImpl': Invocation of init method failed; nested exception is org.quartz.JobPersistenceException: Couldn't store job: Packet for query is too large (2,223 > 1,024). You can change this value on the server by setting the 'max_allowed_packet' variable. [See nested exception: com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for query is too large (2,223 > 1,024). You can change this value on the server by setting the 'max_allowed_packet' variable.]

my.cnf中添加
max_allowed_packet=20M
Access denied for user 'root'@'localhost' (using password: YES)
my.cnf 添加skip-grant-tables
登录后修改密码
[root@vm10-0-0-3 ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 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 [mysql]> update user set authentication_string=password('root') where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1



修改root密码
MySQL [mysql]> update user set authentication_string=password('root') where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

你可能感兴趣的:(环境搭建,mysql)