linux|Linux安装mysql(yum)
Linux安装mysql(yum)
- 作者QQ:67065435 QQ群:821635552
- 安装前的准备
yum install \ vim \ git \ gcc \ gcc-c++ \ wget \ make \ cmake \ automake \ autoconf \ libaio \ libtool \ net-tools \ bison-devel \ libaio-devel \ ncurses-devel \ perl-Data-Dumper \ -y
- 获取源码资源包
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
- 安装源码资源包
rpm -ivh mysql57-community-release-el7-10.noarch.rpm
- 通过资源包安装mysql
yum install mysql-server -y
- 修改文件打开数上限
# 系统文件打开数上限 vim /etc/security/limits.conf* hard nofile 65535 * soft nofile 65535ESC :wq# MySQL文件打开数上限 vim /usr/lib/systemd/system/mysqld.serviceLimitNOFILE=65535ESC :wqsystemctl daemon-reload
- 修改my.conf
vim /etc/my.cnf[client] default-character-set = utf8mb4[mysql] default-character-set = utf8mb4[mysqld] max_connections = 512 tmp_table_size = 256M key_buffer_size = 512M sort_buffer_size = 64M read_buffer_size = 64M thread_cache_size = 64 join_buffer_size = 128M sort_buffer_size = 128M query_cache_size = 512M table_open_cache = 4096M read_rnd_buffer_size = 128M innodb_buffer_pool_size = 128M datadir=/data/mysql log_timestamps = SYSTEM default_storage_engine = InnoDB character-set-server=utf8mb4 init_connect='SET NAMES utf8mb4' collation-server=utf8mb4_unicode_ci character-set-client-handshake=FALSEsymbolic-links=0 log-error=/data/mysql/mysqld.log socket=/data/mysql/mysql.sock pid-file=/data/mysql/mysqld.pid secure_file_priv=/var/lib/mysql-filesserver-id=1 binlog-format=Row expire_logs_days=10 log-bin=/data/mysql/mysql-bin sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONESC :wq
- 创建数据文件目录、所属组、用户改为mysql
mkdir /data mkdir /data/mysql chown -R mysql:mysql /etc/my.cnf chown -R mysql:mysql /data/mysql/ chown -R mysql:mysql /var/*/mysql*
- 修改SELinux
vim /etc/sysconfig/selinuxSELINUX=permissiveESC :wqsetenforce 0
- 启动数据库,生成socket文件
systemctl enable mysqld systemctl start mysqld # 因为配置文件中指定了 log-error=/var/log/mysqld.log # 所以初始密码在如下文件中 /var/log/mysqld.log cat /var/log/mysqld.log|grep password # 结果显示 A temporary password is generated for root@localhost: **************
- 修改数据库初始密码
mysql -u root -p # 输入原始密码 ************** # 设置允许使用弱密码 SET GLOBAL validate_password_policy=0; ALTER USER 'root'@'localhost' IDENTIFIED BY '**************'; GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'%' IDENTIFIED BY '**************' WITH GRANT OPTION; FLUSH PRIVILEGES; QUIT;
- 初始化数据库(除了密码一律选择Y)
# 如果是数据库【安装】则只执行下面这步 mysql_secure_installation# 如果是数据库【升级】则只执行下面这步(**************表示数据库之前的密码) mysql_upgrade -u root -p **************
- 配置防火墙
systemctl enable firewalld systemctl startfirewalld firewall-cmd --permanent --zone=public --add-port=3306/tcp firewall-cmd --reload
- 测试启动、停止、重启mysql
#启用并启动 systemctl enable mysqld systemctl start mysqld #禁用并关闭 systemctl disable mysqld systemctl stop mysqld #启用并重新启动 systemctl enable mysqld systemctl restart mysqld
- 【linux|Linux安装mysql(yum)】设置外部访问密码
# 数据库名-通配符及格式: *[允许操作所有数据库] %pay%[允许操作名字包含'pay'的数据库] mydatabase[仅允许操作'mydatabase'数据库] # 表名-通配符及格式: *[允许操作所有表] %pay%[允许操作名字包含'pay'的表] mytable[仅允许操作'mytable'表] # ip地址-通配符及格式: %/0.0.0.0[允许任意IP访问] xxx.xxx.xxx.xxx[仅限公网访问] 192.168.x.xxx[仅限局域网访问] localhost/127.0.0.1/::1[仅限本机访问]# 数据库授权格式 GRANT 权限名 ON 数据库名.数据表名 TO '数据用户'@'访问IP' IDENTIFIED BY '用户密码' WITH GRANT OPTION; # 为任意数据库表 任意操作 分配root用户,仅限本地访问 GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '**************' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '**************' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'::1' IDENTIFIED BY '**************' WITH GRANT OPTION; # 为任意数据库表 任意操作 分配mysql用户,任意IP访问(安装调试阶段、本地开发使用,用后即删) GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'%' IDENTIFIED BY '**************' WITH GRANT OPTION; # 为任意数据库表 增删改查 分配单独用户,为不同的业务分配专属用户 GRANT INSERT ON *.* TO 'insert1'@'127.0.0.1' IDENTIFIED BY '**************' WITH GRANT OPTION; GRANT DELETE ON *.* TO 'delete1'@'127.0.0.1' IDENTIFIED BY '**************' WITH GRANT OPTION; GRANT UPDATE ON *.* TO 'update1'@'127.0.0.1' IDENTIFIED BY '**************' WITH GRANT OPTION; GRANT SELECT ON *.* TO 'select1'@'127.0.0.1' IDENTIFIED BY '**************' WITH GRANT OPTION; # 刷新权限 FLUSH PRIVILEGES;
推荐阅读
- Mac安装Chromedriver
- MongoDB,Wondows下免安装版|MongoDB,Wondows下免安装版 (简化版操作)
- MAC安装Mongo
- Linux下面如何查看tomcat已经使用多少线程
- Beego打包部署到Linux
- 【Hadoop踩雷】Mac下安装Hadoop3以及Java版本问题
- react|react 安装
- VueX--VUE核心插件
- python-安装sublime遇到异常
- typeScript入门基础介绍