CentOS 7 YUM 在线安装版
1.wget 下载
2.rpm -Uvh mysql57-community-release-el7-10.noarch.rpm 安装 rpm 源
3.yum install -y MySQL-community-server 取决于网速
4.systemctl start mysqld.service / service mysqld start 启动 MySQL
5.service mysqld status 查看启动状态
6.
7.grep 'temporary password' /var/log/mysqld.log 查看 MySQL 临时密码
8.MySQL -uroot -p 登录 MySQL
9.ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
修改密码 -> 提示: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
10. set global validate_password_policy=0;
11. set global validate_password_length=1; 重复 9 步骤 ---> 修改密码
12.GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION; 开放远程登录
FLUSH PRIVILEGES; 刷新配置
13. 关闭防火墙
查看防火墙 systemctl status firewalld.service / service iptables status status/start/restart/stop --option
14. 修改配置文件
vi /etc/my.cnf 编辑 my.cnf / 没有手动创建文件
正确配置
- # For advice on how to change settings please see
- # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
- [mysqld]
- character_set_server=utf8
- #[client]
- #default-character-set=utf8
- #
- # 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
15.systemctl status mysqld.service 查看 MySQL 状态 status/start/stop/restart -- option
CentOS glib 版安装
1.tar -zvxf MySQL-5.7.26-Linux-glibc2.12-x86_64.tar.gz 解压
2.mv MySQL-5.7.26-Linux-glibc2.12-x86_64/*/usr/local/MySQL 移动文件
3.groupadd user 添加用户
4.useradd -r -g MySQL MySQL 添加用户组
5.rpm -qa | grep libaio 检查 libaio
6.yum -y install libaio 安装 libaio
7.vi /etc/my.cnf 编辑 my.cnf / 没有手动创建文件
- [MySQL]
- # 设置 MySQL 客户端默认字符集
- default-character-set=utf8
- socket=/var/lib/MySQL/MySQL.sock
- [mysqld]
- #skip-name-resolve
- # 设置 3306 端口
- port = 3306
- socket=/var/lib/MySQL/MySQL.sock
- # 设置 MySQL 的安装目录
- basedir=/usr/local/MySQL
- # 设置 MySQL 数据库的数据的存放目录
- datadir=/usr/local/MySQL/data
- # 允许最大连接数
- max_connections=200
- # 服务端使用的字符集默认为 8 比特编码的 latin1 字符集
- character-set-server=utf8
- # 创建新表时将使用的默认存储引擎
- #default-storage-engine=MyIsam
- default-storage-engine=INNODB
- #lower_case_table_name=1
- max_allowed_packet=16M
8.mkdir data 创建目录
- [[email protected] MySQL]# chown -R MySQL:MySQL ./ 授权目录拥有者
- [[email protected] MySQL]# ./bin/mysqld --initialize --user=MySQL --basedir=/usr/local/MySQL/ --datadir=/usr/local/MySQL/data/ 初始化
11. 成功图示
12.[[email protected] MySQL]# cp ./support-files/MySQL.server /etc/rc.d/init.d/mysqld
13. 增加 mysqld 服务控制脚本执行权限:[[email protected] MySQL]# chmod +x /etc/rc.d/init.d/mysqld
14. 将 mysqld 服务加入到系统服务:[[email protected] MySQL]# chkconfig --add mysqld
15. 检查 mysqld 服务是否已经生效:[[email protected] MySQL]# chkconfig --list mysqld
- 16.[[email protected] MySQL]# service mysqld start 启动 MySQL 提示 err 目录 pid 不存在
- Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
- 2019-07-04T02:40:27.646818Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
- ERROR! The server quit without updating PID file (/usr/local/MySQL/data/localhost.localdomain.pid).
- 17.[[email protected] MySQL]# mkdir /var/lib/MySQL
- [[email protected] MySQL]# chown -R MySQL /var/lib/MySQL
18. 再次启动
19. 登录 提示 command
20. 进行软链接
ln -s /usr/local/MySQL/bin/MySQL /usr/bin
21.
22. 先进行密码设置 ,
SET PASSWORD = PASSWORD('123456'); 设置初始密码. 不然操作不了数据库
23. 提示 You must reset your password using ALTER USER statement before executing this statement.
24
25.use MySQL 切到系统库
26.MySQL> grant all privileges on *.* to [email protected]"%" identified by "123456" with grant option; 授权远程登录
Query OK, 0 rows affected, 1 warning (0.00 sec)
27.MySQL> flush privileges; 刷新
Query OK, 0 rows affected (0.00 sec)
28. systemctl status mysqld.service MySQL 状态
29.systemctl status firewalld.service 关闭防火墙
30.
完毕. 整理 OK. 亲测可用. 注意以上安装都没有配置环境变量. 虚拟学习而已
来源: http://www.bubuko.com/infodetail-3112916.html