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

此处如果报如下错误

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

 

发布了56 篇原创文章 · 获赞 23 · 访问量 6万+
展开阅读全文

linux 安装 mysql 后出现的问题

05-19

我的安装步骤如下: 1. 下载mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz 文件 2.解压_到 /usr/local/mysqlService/目录下 ,解压后的文件夹重命名为mysql 3、运行安装目录下面的 scripts/mysql_install_db 进行安装 4、编辑 /etc/my.cnf 配置如下: [root@localhost ~]# cat /etc/my.cnf [client] socket = /tmp/mysql.sock [mysqld] #character-set-server=utf8 datadir=/usr/local/mysqlService/mysql/data basedir=/usr/local/mysqlService/mysql socket=/tmp/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # 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/mysqlService/mysql/log/mysqld.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d [root@localhost ~]# 5、 /etc/my.cnf 中的 socket = /tmp/mysql.sock 是我照着网上写的,我并没有找到mysql.sock 这个文件 6、开始运行 #service mysql start 报错: 170518 17:11:11 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysqlService/mysql/data 2017-05-18 17:11:11 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for m ore details). 2017-05-18 17:11:11 0 [Note] /usr/local/mysqlService/mysql/bin/mysqld (mysqld 5.6.33) starting as process 27678 ... 2017-05-18 17:11:11 27678 [Note] Plugin 'FEDERATED' is disabled. /usr/local/mysqlService/mysql/bin/mysqld: Table 'mysql.plugin' doesn't exist 2017-05-18 17:11:11 27678 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 2017-05-18 17:11:11 27678 [Note] InnoDB: Using atomics to ref count buffer pool pages 2017-05-18 17:11:11 27678 [Note] InnoDB: The InnoDB memory heap is disabled 2017-05-18 17:11:11 27678 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2017-05-18 17:11:11 27678 [Note] InnoDB: Memory barrier is not used 2017-05-18 17:11:11 27678 [Note] InnoDB: Compressed tables use zlib 1.2.3 2017-05-18 17:11:11 27678 [Note] InnoDB: Using Linux native AIO 2017-05-18 17:11:11 27678 [Note] InnoDB: Using CPU crc32 instructions 2017-05-18 17:11:11 27678 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2017-05-18 17:11:11 27678 [Note] InnoDB: Completed initialization of buffer pool 2017-05-18 17:11:11 27678 [Note] InnoDB: Highest supported file format is Barracuda. 2017-05-18 17:11:11 27678 [Note] InnoDB: Log scan progressed past the checkpoint lsn 49463 2017-05-18 17:11:11 27678 [Note] InnoDB: Database was not shutdown normally! 2017-05-18 17:11:11 27678 [Note] InnoDB: Starting crash recovery. 2017-05-18 17:11:11 27678 [Note] InnoDB: Reading tablespace information from the .ibd files... 2017-05-18 17:11:11 27678 [Note] InnoDB: Restoring possible half-written data pages 2017-05-18 17:11:11 27678 [Note] InnoDB: from the doublewrite buffer... InnoDB: Doing recovery: scanned up to log sequence number 1600607 2017-05-18 17:11:11 27678 [Note] InnoDB: Starting an apply batch of log records to the database... InnoDB: Progress in percent: 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 7 4 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 InnoDB: Apply batch completed 2017-05-18 17:11:12 27678 [Note] InnoDB: 128 rollback segment(s) are active. 2017-05-18 17:11:12 27678 [Note] InnoDB: Waiting for purge to start 2017-05-18 17:11:12 27678 [Note] InnoDB: 5.6.33 started; log sequence number 1600607 2017-05-18 17:11:12 27678 [Note] Server hostname (bind-address): '*'; port: 3306 2017-05-18 17:11:12 27678 [Note] IPv6 is available. 2017-05-18 17:11:12 27678 [Note] - '::' resolves to '::'; 2017-05-18 17:11:12 27678 [Note] Server socket created on IP: '::'. 2017-05-18 17:11:12 27678 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 170518 17:11:12 mysqld_safe mysqld from pid file /usr/local/mysqlService/mysql/data/localhost.localdomain.pid ended 到目前为止,一直报这个错误,我目前还觉得是哪里配置出现了问题,但是网上找了一天,一点进展都没有。希望大神们看到能够帮助我解决这个问题。 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览