当前位置:   article > 正文

centos7安装配置mysql的正确姿势_mariadb-5.5.68-1.el7.x86_64

mariadb-5.5.68-1.el7.x86_64

centos7 安装mysql有时候会出现莫名其妙的错误,好多时候可能不成功,这里简单记录一下正确配置的过程。

centos自带的是 mariadb,先查看是否还在,先卸载:

  1. rpm -qa|grep mariadb
  2. um remove -y mariadb-libs-5.5.68-1.el7.x86_64
  1. [root@localhost opt]# rpm -qa|grep mariadb
  2. mariadb-libs-5.5.68-1.el7.x86_64
  3. mariadb-5.5.68-1.el7.x86_64
  4. mariadb-server-5.5.68-1.el7.x86_64
  1. [root@localhost opt]# yum remove -y mariadb-libs-5.5.68-1.el7.x86_64
  2. Loaded plugins: fastestmirror, langpacks
  3. Resolving Dependencies
  4. --> Running transaction check
  5. ---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be erased
  6. --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64
  7. --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
  8. --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64
  9. --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
  10. --> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-5.5.68-1.el7.x86_64
  11. --> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-server-5.5.68-1.el7.x86_64
  12. --> Running transaction check
  13. ---> Package mariadb.x86_64 1:5.5.68-1.el7 will be erased
  14. ---> Package mariadb-server.x86_64 1:5.5.68-1.el7 will be erased
  15. ---> Package perl-DBD-MySQL.x86_64 0:4.023-6.el7 will be erased
  16. ---> Package postfix.x86_64 2:2.10.1-7.el7 will be erased
  17. --> Finished Dependency Resolution
  18. Dependencies Resolved
  19. ==============================================================================================================================================================
  20. Package Arch Version Repository Size
  21. ==============================================================================================================================================================
  22. Removing:
  23. mariadb-libs x86_64 1:5.5.68-1.el7 @base 4.4 M
  24. Removing for dependencies:
  25. mariadb x86_64 1:5.5.68-1.el7 @base 49 M
  26. mariadb-server x86_64 1:5.5.68-1.el7 @base 58 M
  27. perl-DBD-MySQL x86_64 4.023-6.el7 @base 323 k
  28. postfix x86_64 2:2.10.1-7.el7 @anaconda 12 M
  29. Transaction Summary
  30. ==============================================================================================================================================================
  31. Remove 1 Package (+4 Dependent packages)
  32. Installed size: 124 M
  33. Downloading packages:
  34. Running transaction check
  35. Running transaction test
  36. Transaction test succeeded
  37. Running transaction
  38. Erasing : 1:mariadb-server-5.5.68-1.el7.x86_64 1/5
  39. warning: /var/log/mariadb/mariadb.log saved as /var/log/mariadb/mariadb.log.rpmsave
  40. Erasing : 1:mariadb-5.5.68-1.el7.x86_64 2/5
  41. Erasing : perl-DBD-MySQL-4.023-6.el7.x86_64 3/5
  42. Erasing : 2:postfix-2.10.1-7.el7.x86_64 4/5
  43. Erasing : 1:mariadb-libs-5.5.68-1.el7.x86_64 5/5
  44. Verifying : 1:mariadb-server-5.5.68-1.el7.x86_64 1/5
  45. Verifying : 2:postfix-2.10.1-7.el7.x86_64 2/5
  46. Verifying : 1:mariadb-libs-5.5.68-1.el7.x86_64 3/5
  47. Verifying : 1:mariadb-5.5.68-1.el7.x86_64 4/5
  48. Verifying : perl-DBD-MySQL-4.023-6.el7.x86_64 5/5
  49. Removed:
  50. mariadb-libs.x86_64 1:5.5.68-1.el7
  51. Dependency Removed:
  52. mariadb.x86_64 1:5.5.68-1.el7 mariadb-server.x86_64 1:5.5.68-1.el7 perl-DBD-MySQL.x86_64 0:4.023-6.el7 postfix.x86_64 2:2.10.1-7.el7
  53. Complete!
  54. [root@localhost opt]# rpm -qa|grep mariadb
  55. [root@localhost opt]# ls

下载mysql安装包,需要下载社区版。

可以到这里去找:

MySQL :: Download MySQL Community Server (Archived Versions)

 也可以直接下载:

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar

下载后获得这个文件:

mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar

解压缩。

# 按照以下顺序进行安装,因为它们之间存在依赖关系

         common --> libs --> clients --> server

  1. yum -y install mysql-community-common-*
  2. yum -y install mysql-community-libs-5.7.30-1.el7.x86_64.rpm
  3. yum -y install mysql-community-client-5.7.30-1.el7.x86_64.rpm
  4. yum -y install mysql-community-server-5.7.30-1.el7.x86_64.rpm

初始化之前修改mysql的配置文件/etc/my.cnf

启动mysql服务:

systemctl start mysqld.service

 执行mysql,发现已经成功进入:

  1. [root@localhost ~]# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 2
  4. Server version: 5.7.30-log MySQL Community Server (GPL)
  5. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> exit
  11. Bye
  12. [root@localhost ~]# rpm -qi mysql-server
  13. package mysql-server is not installed
  14. [root@localhost ~]# rpm -e mysql
  15. error: package mysql is not installed
  16. [root@localhost ~]# service mysqld status
  17. Redirecting to /bin/systemctl status mysqld.service
  18. ● mysqld.service - MySQL Server
  19. Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
  20. Active: active (running) since Sat 2022-01-22 04:28:48 PST; 5min ago
  21. Docs: man:mysqld(8)
  22. http://dev.mysql.com/doc/refman/en/using-systemd.html
  23. Process: 44384 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  24. Process: 44362 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
  25. Main PID: 44387 (mysqld)
  26. Tasks: 28
  27. Memory: 192.1M
  28. CGroup: /system.slice/mysqld.service
  29. └─44387 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
  30. Jan 22 04:28:48 localhost.localdomain systemd[1]: Starting MySQL Server...
  31. Jan 22 04:28:48 localhost.localdomain systemd[1]: Started MySQL Server.

查看日志,发现报错:

  1. [root@localhost ~]# tail /var/log/mysqld.log
  2. 2022-01-22T04:28:48.820789-08:00 0 [ERROR] Native table 'performance_schema'.'session_status' has the wrong structure
  3. 2022-01-22T04:28:48.820801-08:00 0 [ERROR] Native table 'performance_schema'.'variables_by_thread' has the wrong structure
  4. 2022-01-22T04:28:48.820813-08:00 0 [ERROR] Native table 'performance_schema'.'global_variables' has the wrong structure
  5. 2022-01-22T04:28:48.820858-08:00 0 [ERROR] Native table 'performance_schema'.'session_variables' has the wrong structure
  6. 2022-01-22T04:28:48.820968-08:00 0 [ERROR] Incorrect definition of table mysql.db: expected column 'User' at position 2 to have type char(32), found type char(16).
  7. 2022-01-22T04:28:48.820980-08:00 0 [ERROR] mysql.user has no `Event_priv` column at position 28
  8. 2022-01-22T04:28:48.821074-08:00 0 [ERROR] Incorrect definition of table mysql.event: expected column 'sql_mode' at position 14 to have type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH'), found type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_A
  9. 2022-01-22T04:28:48.821081-08:00 0 [ERROR] Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
  10. 2022-01-22T04:28:48.821359-08:00 0 [Note] /usr/sbin/mysqld: ready for connections.
  11. Version: '5.7.30-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)

进行远程访问授权,发现报错:

  1. mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
  2. ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 45, found 42. Created with MySQL 50568, now running 50730. Please use mysql_upgrade to fix this error.
  3. mysql> exit
  4. Bye

进行修复:

  1. [root@localhost mysql-5.7.30-1.el7.x86_64.rpm-bundle]# mysql_upgrade -u root -p --force
  2. Enter password:
  3. Checking server version.
  4. Running queries to upgrade MySQL server.
  5. mysql_upgrade: (non fatal) [ERROR] 1728: Cannot load from mysql.proc. The table is probably corrupted
  6. mysql_upgrade: (non fatal) [ERROR] 1545: Failed to open mysql.event
  7. Checking system database.
  8. mysql.columns_priv OK
  9. mysql.db OK
  10. mysql.engine_cost OK
  11. mysql.event OK
  12. mysql.func OK
  13. mysql.general_log OK
  14. mysql.gtid_executed OK
  15. mysql.help_category OK
  16. mysql.help_keyword OK
  17. mysql.help_relation OK
  18. mysql.help_topic OK
  19. mysql.host OK
  20. mysql.innodb_index_stats OK
  21. mysql.innodb_table_stats OK
  22. mysql.ndb_binlog_index OK
  23. mysql.plugin OK
  24. mysql.proc OK
  25. mysql.procs_priv OK
  26. mysql.proxies_priv OK
  27. mysql.server_cost OK
  28. mysql.servers OK
  29. mysql.slave_master_info OK
  30. mysql.slave_relay_log_info OK
  31. mysql.slave_worker_info OK
  32. mysql.slow_log OK
  33. mysql.tables_priv OK
  34. mysql.time_zone OK
  35. mysql.time_zone_leap_second OK
  36. mysql.time_zone_name OK
  37. mysql.time_zone_transition OK
  38. mysql.time_zone_transition_type OK
  39. mysql.user OK
  40. Upgrading the sys schema.
  41. Checking databases.
  42. sys.sys_config OK
  43. Upgrade process completed successfully.
  44. Checking if update is needed.

重启服务后,重新授权,正常了。

  1. [root@localhost mysql-5.7.30-1.el7.x86_64.rpm-bundle]# service mysqld restart
  2. Redirecting to /bin/systemctl restart mysqld.service
  3. [root@localhost mysql-5.7.30-1.el7.x86_64.rpm-bundle]# mysql
  4. Welcome to the MySQL monitor. Commands end with ; or \g.
  5. Your MySQL connection id is 2
  6. Server version: 5.7.30-log MySQL Community Server (GPL)
  7. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  12. mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
  13. Query OK, 0 rows affected, 1 warning (0.00 sec)
  14. mysql> show variables like "%char%";
  15. +--------------------------+----------------------------+
  16. | Variable_name | Value |
  17. +--------------------------+----------------------------+
  18. | character_set_client | utf8 |
  19. | character_set_connection | utf8 |
  20. | character_set_database | latin1 |
  21. | character_set_filesystem | binary |
  22. | character_set_results | utf8 |
  23. | character_set_server | latin1 |
  24. | character_set_system | utf8 |
  25. | character_sets_dir | /usr/share/mysql/charsets/ |
  26. +--------------------------+----------------------------+
  27. 8 rows in set (0.01 sec)
  28. mysql> exit
  29. Bye

处理防火墙:

  1. [root@localhost mysql-5.7.30-1.el7.x86_64.rpm-bundle]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
  2. success
  3. [root@localhost mysql-5.7.30-1.el7.x86_64.rpm-bundle]# firewall-cmd --reload
  4. success

远程访问需要root密码,修改密码,发现报错。

  1. mysql> update user set password=password('jumpserver') where user='root';
  2. ERROR 1054 (42S22): Unknown column 'password' in 'field list'
  3. mysql> update user set password=password('123456') where user='root';
  4. ERROR 1054 (42S22): Unknown column 'password' in 'field list'

mysql5.7社区版语法有变更。

  1. mysql> update mysql.user set authentication_string=password('root') where user='root' ;
  2. Query OK, 4 rows affected, 1 warning (0.00 sec)
  3. Rows matched: 5 Changed: 4 Warnings: 1
  4. mysql> flush privileges;
  5. Query OK, 0 rows affected (0.00 sec)
  6. mysql> quit;
  7. Bye

进行验证

连接成功。 

花了大半天时间,用网上很多教程都没有安装成功,这里却安装成功了,因此进行记录。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/88596
推荐阅读
相关标签
  

闽ICP备14008679号