linux 利用yum源安装mysql5.7
前言
- CentOS 7
- MySQL 5.7
- 查找mysql源 http://repo.mysql.com
步驟
添加mysql源
shell> rpm -ivh http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm Retrieving http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm Preparing... ################################# [100%] Updating / installing...1:mysql57-community-release-el7-10 ################################# [100%]注:卸載mysql源 rpm -e --nodeps mysql57-community-release-el7-10.noarch
查看mysql源中的mysql版本
shell> yum info mysql-community-server Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : mysql-community-server Arch : x86_64 Version : 5.7.27 Release : 1.el7 Size : 746 M Repo : installed From repo : mysql57-community Summary : A very fast and reliable SQL database server URL : http://www.mysql.com/ License : Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights: reserved. Under GPLv2 license as shown in the Description field. Description : The MySQL(TM) software delivers a very fast, multi-threaded,: multi-user, and robust SQL (Structured Query Language) database: server. MySQL Server is intended for mission-critical, heavy-load: production systems as well as for embedding into mass-deployed: software. MySQL is a trademark of Oracle and/or its affiliates:: The MySQL software has Dual Licensing, which means you can use the: MySQL software free of charge under the GNU General Public License: (http://www.gnu.org/licenses/). You can also purchase commercial: MySQL licenses from Oracle and/or its affiliates if you do not: wish to be bound by the terms of the GPL. See the chapter: "Licensing and Support" in the manual for further info.:: The MySQL web site (http://www.mysql.com/) provides the latest: news and information about the MySQL software. Also please see: the documentation and the manual for more information.:: This package includes the MySQL server binary as well as related: utilities to run and administer a MySQL server.安裝mysql
shell> yum install mysql-server啟動mysql
shell> systemctl start mysqld查看mysql是否啟動
shell> ps -ef | grep mysql mysql 26517 1 0 13:13 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid root 26578 25533 0 13:13 pts/1 00:00:00 grep --color=auto mysql或
shell> netstat -tlnp | grep mysql tcp6 0 0 :::3306 :::* LISTEN 26517/mysqld設置root賬戶密碼
因為mysql5.7為了安全性的考慮,在安裝的時候隨機生成了一個初始密碼,放在/var/log/mysqld.log文件中。查詢/var/log/mysqld.log文件中的初始密碼。
初始密碼為:,MuwPzvkf0;y
修改root密碼為:root
mysql -uroot -p,MuwPzvkf0;y mysql> set password=password('root'); ---------------------------------------- Query OK, 0 rows affected, 1 warning (0.00 sec)在重新設置密碼的時候,如果密碼強度不夠高,會提示不安全,需要重新設置。像root,123456都無法設置了。
MySQL5.6.6版本之后增加了密碼強度驗證插件validate_password,相關參數設置的較為嚴格。使用了該插件會檢查設置的密碼是否符合當前設置的強度規則,若不滿足則拒絕設置。影響的語句和函數有:create user,grant,set password,password(),old password。
測試時為了方便,確需設置簡單密碼時,可以參考 mysql5.7修改root密碼 進行設置。
也可以參考:https://blog.csdn.net/u014236541/article/details/78244601和https://www.cnblogs.com/ivictor/p/5142809.html
進入mysql
shell> mysql -uroot -proot mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.27 MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase 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> quit Bye設置mysql數據編碼格式為utf8。
編輯my.cnf
shell> vi /etc/my.cnf在my.cnf中修改內容
[mysqld] character_set_server=utf8重啟mysql后,登錄mysql查看設置結果:
mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';+--------------------------+-----------------+ | Variable_name | Value | +--------------------------+-----------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +--------------------------+-----------------+ 10 rows in set (0.01 sec)執行mysql_secure_installation
安裝完mysql-server后,進入生產環境之前,一定要運行一次mysql_secure_installation。運行mysql_secure_installation會執行幾個設置:
- 為root用戶設置密碼
- 刪除匿名賬號
- 取消root用戶遠程登錄
- 刪除test庫和對test庫的訪問權限
- 刷新授權表使修改生效
參考:MySQL----mysql_secure_installation 安全配置向導
匿名賬戶參考:https://www.cnblogs.com/wzzkaifa/p/7000808.html
其它
啟動mysql:systemctl start mysqld
停止mysql:systemctl stop mysqld
重啟mysql:systemctl restart mysqld
查看mysql狀態:systemctl status mysqld
mysql服務開啟:systemctl enable mysqld
mysql服務關閉:systemctl disable mysqld
查看mysql服務是否開啟:systemctl list-unit-files|grep mysqld
查看mysql版本:mysql -V
my.cnf配置文件讀取順序:mysqld --help --verbose 2> /dev/null | grep -A1 ‘Default options’
總結
以上是生活随笔為你收集整理的linux 利用yum源安装mysql5.7的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 泰国与丰田合作发展电动汽车业务,计划试行
- 下一篇: 美股周四:三大股指齐跌,Arm跌超5%,