linux 安装mysql5.7

部分参考自:https://blog.csdn.net/qq_37598011/article/details/93489404   感谢分享

下载mysql:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

 解压文件

 tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz 

移动位置并重命名

mv mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql

在/usr/local/mysql/下创建my.cnf文件,在/usr/local/下创建mysqlData文件夹

[mysqld]
bind-address=0.0.0.0
port=3306
user=mysqlUser
basedir=/usr/local/mysql
datadir=/usr/local/mysqlData
socket=/tmp/mysql.sock
log-error=/usr/local/mysqlData/mysql.err
pid-file=/usr/local/mysqlData/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

增加分组和用户

groupadd mysql
useradd -r -g mysql mysqlUser

给创建的mysqlData赋权限

chown mysqlUser:mysql -R /usr/local/mysqlData

初始化mysql

./mysqld --defaults-file=/usr/local/mysql/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysqlData/ --user=mysqlUser --initialize

获取密码

[root@root bin]# cat /usr/local/mysqlData/mysql.err
2020-03-26T04:21:35.426767Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-03-26T04:21:35.534209Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-26T04:21:35.601590Z 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: 47b336bb-6f19-11ea-b44f-000c29b61d7e.
2020-03-26T04:21:35.605321Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-03-26T04:21:36.173825Z 0 [Warning] CA certificate ca.pem is self signed.
2020-03-26T04:21:36.267144Z 1 [Note] A temporary password is generated for root@localhost: %jeLifZ=o5lA

将mysql启动方式改为服务并启动

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

此处如果报如下错误

扫描二维码关注公众号,回复: 10292354 查看本文章
Starting MySQL.The server quit without updating PID file (/usr/local/mysqlData/mysql.pid)

则将/etc/my.cnf删除从序列化开始重新执行一遍

修改数据默认密码

[root@root mysqlData]# cd /usr/local/mysql/bin/
[root@root bin]# ./mysql -u root -p
mysql> SET PASSWORD = PASSWORD('1234');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

设置数据库可以远程访问

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> use mysql
Database changed

mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

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)

注意打开端口号再访问;

设置开机自启动

[root@root~]# chmod +x /etc/init.d/mysql
[root@root~]# chkconfig --add mysql
[root@root~]# chkconfig --list
发布了50 篇原创文章 · 获赞 23 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/u010833154/article/details/105113003