Loading

二进制安装 MySQL

1 准备工作

检查系统中的Mysql或mariadb,如果存在将其卸载

rpm -qa | grep mysql
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

安装依赖包

yum install libaio    //centos7及以上默认已安装

创建mysql用户

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

 

2 下载安装二进制包

官网链接: https://dev.mysql.com/downloads/mysql/

此处版本选择: mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
tar zxf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local
mv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql           //重命名

 

3 修改环境变量

vi /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile.d/mysql.sh

 

4 创建数据目录并授权

mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/data
chmod -R 770 /usr/local/mysql/data

 

5 编辑配置文件

vim /etc/my.cnf

[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
server_id=6
port=3306
socket=/tmp/mysql.sock
character-set-server=utf8
[mysql]
socket=/tmp/mysql.sock

 

6 mysql初始化

mysqld --initialize --user=mysql  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data        //初始化

2022-04-02T00:50:25.139543Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-04-02T00:50:25.604456Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-04-02T00:50:25.656489Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-04-02T00:50:25.860185Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e263dee2-b21e-11ec-8b0b-000c298d8720.
2022-04-02T00:50:25.861588Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-04-02T00:50:26.388954Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-04-02T00:50:26.388973Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-04-02T00:50:26.389998Z 0 [Warning] CA certificate ca.pem is self signed.
2022-04-02T00:50:26.561596Z 1 [Note] A temporary password is generated for root@localhost: Xd5L-lmn<yi/

 

7 用systemctl管理mysql

vi /etc/systemd/system/mysqld.service

[Unit]
Description=MySQL 
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

 

8 测试 设置root密码 远程登录

systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld    //没启起来登录会报错找不到sockt文件
mysql -uroot -p         //登录

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';   //改密码

mysql> use mysql;
mysql> select user,host from user; 
mysql> update user set host='%' where user='root';      //修改远程登录权限
mysql> flush privileges;        //刷新权限
posted @ 2022-04-02 05:59  Tayo  阅读(121)  评论(0)    收藏  举报