CentOS7下MySQL离线安装和使用
文章目录
MySQL是非常流行的关系型数据库,同时也是最受欢迎的开源数据库,使用的公司已经数不过来了。作为程序员必备的技能,那么就需要会快速的使用和安装,下面介绍一种离线安装和快速开始使用。
使用
-
下载离线安装包
链接:https://pan.baidu.com/s/1mps3sGHdweGrG-DTzE2n3Q 密码:a3rc
如果失效了记得留言给本站,本站会收到你的回复的。
下载好文件放到服务器上自己记得住的地址:比如 /home/admin
-
卸载CentOS7自带的Mariadb数据库,可能会有文件冲突
1 2 3 4 5
# 查找下现有系统的具体的名称 rpm -qa | grep mariadb mariadb-libs-xxxxxxx # 删除查找到的文件 rpm -e --nodeps mariadb-libs-xxxxxxx
-
开始安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# 安装一些必要的库和工具 yum install -y perl-Module-Install.noarch yum -y install perl yum -y install libaio yum install libnuma* yum install net-tools -y # 此离线包的路径根据实际的来 cd /home/admin/MySQL rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm # 安装完成,如果有报错,缺少库,自己使用yum安装即可 # 启动服务 service mysqld start # 或者另一个启动服务 systemctl start mysqld # 记录下默认的数据库密码,后面登录的时候用 cat /var/log/mysqld.log |grep password
-
开始简单的配置一些配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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
# 修改密码 mysql -u root -p # 输入刚才的默认密码 # 输入新的密码 SET PASSWORD = PASSWORD('PassPassword_123’); exit; # 暂停服务 service mysqld stop # 开始更新配置文件 以下 // 标级的都是新增的地方 vim /etc/my.conf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysql] // default-character-set=utf8mb4 // [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid transaction-isolation = READ-COMMITTED // max_allowed_packet=256M // innodb_log_file_size=2G // innodb_buffer_pool_size=512M // innodb_file_per_table=1 // collation-server=utf8mb4_unicode_ci // character_set_server=utf8mb4 // default-storage-engine=INNODB // innodb_default_row_format=DYNAMIC // innodb_large_prefix=ON // innodb_file_format=Barracuda // binlog_format=row // performance_schema_max_table_instances=400 // table_definition_cache=400 // table_open_cache=256
-
重新启动服务
1 2
# 开启服务 service mysqld start
-
命令行进入查看一些参数状态
1 2 3 4 5 6 7 8 9 10 11
# 登录数据库 mysql -u root -p # 查看一些编码配置 SHOW VARIABLES LIKE 'character%'; # 查看包的最大限制配置 SHOW VARIABLES LIKE '%max_allowed_packet%'; # 查看一些超时配置 SHOW GLOBAL VARIABLES LIKE '%timeout%';
-
可以创建一个管理员来远程使用
1 2
GRANT ALL ON *.* TO 'admin'@'%' IDENTIFIED BY 'Password_123' WITH GRANT OPTION; FLUSH PRIVILEGES;
提示
关闭服务器的防火墙
|
|
同步服务器的时间
|
|
总结
MySQL的配置和调优有很多,这里只是介绍了简单的使用和安装,可以快速的开始拥有一个可以测试和小项目的使用数据库环境了。后续会继续分享一些不同场景下的调优和使用技巧。
文章作者 拉斐
永久链接 https://www.7benshu.com/post/2020/08/18e815414542a944418f05f74d4f3cfee1/
版权声明
本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。
上次更新 2020-08-18
7本书-公众号