rpm安装MySQL
1、 事先下载并安装MySQL官方的 Yum Repository
[root@localhost ~]# dnf install mysql80-community-release-el8-4.noarch.rpm
2、 直接安装mysql-server
[root@localhost ~]# dnf install mysql-server
3、 启动服务
[root@localhost ~]# systemctl start mysqld.service
4、 查看临时密码
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
5、 使用临时密码进行登录
[root@localhost ~]# mysql -uroot -p
Enter password: 临时密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.30
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql>
6、 如果需要更改密码,则使用下面语句
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
更改之后,则可以使用新密码登录。
如果没有找到日志文件,则可以查找 /var/log/mysql/mysqld.log,如果没有密码,则默认是空密码。sys
源码安装数据库
S>groupadd myq1
S> useradd -r -g mysq1-s /bin/false mysql
S> tar zxvfmysq1-VERSION.tar.gz
S>cd mysql-VERSION
S> mkdir bld
S> cd bld
S> cmake ..
S> make;make install
S>cd /usr/local/mysql
S>mkdir mysql-files
S> chown mysql:mysql mysql-files
S>chmod 750 mysql-files
S>bin/mysqld --initialize--user=mysql S>bin/mysq1_ssl_rsa_setup
S>bin/mysq1d_safe --user=mysq1 &
S>cp support-files/mysqlserver /etc/init.d/mysqlserver
二进制安装
1、下载glibc版本的Mysql
mysql-5.7.14-linux-glibc2.5-x86_64.tar
2、新建用户以安全方式运行进程
groupadd -r -g 306 mysql
useradd -g 306 -r -u 306 mysql
3、安装并初始化mysql
[root@localhost ~]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
[root@localhost local]# ln -sv mysql-5.7.14-linux-glibc2.5-x86_64 mysql
"mysql" -> "mysql-5.7.14-linux-glibc2.5-x86_64"
[root@localhost local]# chown -R mysql.mysql mysql/*
初始化
mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --
datadir=/usr/local/mysql/data
注意记录临时密码:
2019-09-30T07:54:09.437644Z 1 [Note] A temporary password is generated for
root@localhost: Di23xhiKVt-W
4、为mysql提供主配置文件
[root@localhost local]# cd /usr/local/mysql
[root@localhost mysql]# \cp support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
添加如下行指定mysql数据文件的存放位置:
datadir = /usr/local/mysql/data
5、为mysql提供sysv服务脚本
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod +x
/etc/rc.d/init.d/mysqld
6、启动mysql
# chkconfig --add mysqld --添加为系统服务
# chkconfig mysqld on --开机自启动
systemctl start mysqld
7、将mysql的bin目录加入PATH环境变量,编辑/etc/profile文件 使用mysql客户端命令
[root@localhost mysql]# mysql
-bash: mysql: 未找到命令
由于PATH环境变量中没有添加,因此有两种方式: 一种是用绝对路径,如下:
/usr/local/mysql/bin/mysql
第一种用起来比较麻烦,我们下面用第二种添加到PATH
# cd /etc/profile.d/
# vim mysql.sh
• 添加如下内容
export PATH=$PATH:/usr/local/mysql/bin
# source mysql.sh
yum安装MySQL
1、下载并安装MySQL官方的 Yum Repository
[root@localhost ~]# wget -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2、使用yum安装MySQL
[root@localhost ~]# yum install -y mysql57-community-release-el7-10.noarch.rpm
[root@localhost ~]# yum -y install mysql-community-server