栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux安装mysql5.7

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux安装mysql5.7

一、安装前准备
  1. 检查是否已经安装过mysql

    rpm -qa | grep mysql
    

    如果存在,需要删除命令后面为Mysql目录

    rpm -e --nodeps mysql-xxxx
    
  2. 查询所有mysql对应的文件夹

    whereis mysqlm
    find / -name mysql
    #删除相关目录和文件
    rm -rf /usr/bin/mysql /usr/include/mysql /data/mysql /data/mysql/mysql
    #验证是否删除完毕
    whereis mysqlm
    find / -name mysql
    
  3. 检查mysql用户组和用户是否存在,如果没有,则新建

    cat /etc/group | grep mysql
    cat /etc/passwd |grep mysql
    groupadd mysql
    useradd -r -g mysql mysql
    

​ 4.从官网下载安装包
下载路径:https://dev.mysql.com/downloads/mysql/

也可以使用wget命令下载

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
二、安装mysql

1.解压至/usr/local路径下

cp mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz /usr/local/
cd /usr/local/
tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql

2.在/usr/local/mysql下创建data目录

mkdir data

3.修改mysql文件夹下所有的目录及文件夹的所有者和所属组

chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql

4.编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时的密码)

cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql

输出:

2022-05-09T08:24:12.018867Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-05-09T08:24:12.277490Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-05-09T08:24:12.317997Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-05-09T08:24:12.417564Z 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: 67f794b3-cf71-11ec-93cf-000c29ae8820.
2022-05-09T08:24:12.418586Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-05-09T08:24:13.097077Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-05-09T08:24:13.097094Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-05-09T08:24:13.097605Z 0 [Warning] CA certificate ca.pem is self signed.
2022-05-09T08:24:13.208849Z 1 [Note] A temporary password is generated for root@localhost: =t#-JHgwa4L(

5.编辑配置文件my.cnf ,添加配置如下:

cat >>/etc/my.cnf <<-EOF
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
lower_case_table_names=1
character_set_server=utf8
lower_case_table_names=0
character_set_server=utf8
EOF

6.启动mysql服务

/usr/local/mysql/support-files/mysql.server start

有如下字样说明启动成功:

[root@localhost bin]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
 SUCCESS!

7.添加软连接,并重启mysql服务

ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart

8.登录mysql,修改密码(默认密码是步骤4生成的)

mysql -u root -p
mysql> set password  for root@localhost =password('1');
Query OK, 0 rows affected, 1 warning (0.00 sec)

9.开放远程连接

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 -A

Database changed
mysql> update user set user.Host = '%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

10.开启开机自启动

#将服务文件拷贝到init.d下,并重命名为mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#赋予可执行权限
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list

11.如果需要免密登录,则在my.cnf中添加如下配置

cat >>/etc/my.cnf <<-EOF
[client]
user = root
password = 1
EOF

如果需要优化命令行显示效果,可以在my.cnf中添加节点:

cat >>/etc/my.cnf <<-EOF
[mysql]
prompt="\u@\h [\d]>"
EOF
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/871178.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号