一、MYSQL8.0安装
1、查看是否已安装mysql:
rpm -qa | grep mysql
删除已安装mysql
yum remove xxxx
查找mysql相关目录
find / -name mysql
删除相关目录
rm -rf xxxx
2、下载官方msyql包
a)地址:https://dev.mysql.com/downloads/repo/yum/
下载后拷贝/复制到linux,可以使用xftp软件进行操作。
或者复制链接在linux下载:
wget xxxxxx复制链接地址
b)安装mysql包
yum -y install mysql-xxxxxx
c)安装mysql服务
yum -y install mysql-community-server
d)启动mysql服务
systemctl start mysqld.service
如果错误可以尝试进行设置权限
chown mysql:mysql -R /var/lib/mysql
然后再一次尝试重启服务
e)查看运行状态
service mysqld status
3、查看初始化随机密码:
cat /var/log/mysqld.log | grep password
4、安装mysql配置文件
mysql_secure_installation
a)在下方输入mysql随机密码
b)新建mysql密码和验证密码
5、跳过初始化随机密码:vi /etc/my.cnf
在mycnf文件下添加skip-grant-tables
6、修改初始化密码(高版本mysql)
密码尽量复杂些(大小写加符号)。
ALTER USER "root"@"localhost" IDENTIFIED BY "Mysqlabc_123";
密码修改成功。然后exit/quit退出数据库尝试用设置的密码登录。
二、MYSQL5.7安装
1、检查是否安装过mysql
#>rpm -qa | grep mysql
删除mysql
#> rpm -e --nodeps mysql-libs-版本
2、mysql文件查找
#>find / -name mysql
#>whereis mysql
查看创建MYSQL用户组和用户
#> cat /etc/group | grep mysql
#>cat /etc/passwd | grep mysql
#>groupadd mysql
#>useradd -r -g mysql mysql
3、下载mysql包
#>wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
解压mysql压缩包
#> tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
4、解压移动文件到usr下
#>mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
创建data目录
#>mkdir /usr/local/mysql/data
5、更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限
#>chown -R mysql:mysql /user/local/mysql
#>chmod -R 775 /usr/local/mysql
6、编译安装并初始化mysql,记住初始化输出日志末尾的密码
#>cd /usr/local/mysql/bin
#>./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
7、启动mysql服务器
#>/usr/local/mysql/support-files/mysql.server start
查询服务
#>ps -ef | grep mysql
#>ps -ef | grep mysqld
结束进程
#>kill -9 PID
8、添加软连接,并重新启动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
mysql的my.cnf配置文件
#dvice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
explicit_defaults_for_timestamp=true
# 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
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
# port = .....
# server_id = .....
# socket = .....
character-set-server=utf8
# 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
运行如有报错信息:
例:warning: World-writable config file /etc/my.cnf is ignored
修改:#>chmod 644 /etc/my.cnf
9、登录mysql密码为刚才的临时密码
mysql -u root -p
进入mysql后,执行任何指令都会报错,提示修改临时密码
修改临时密码
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql' PASSWORD EXPIRE NEVER;
刷新权限
mysql>flush privileges;
10、开放远程连接
mysql>use mysql;
mysql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
11、开机自启
1、将服务文件拷贝到init.d下,并重命名为mysql
#>cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
#> chmod +x /etc/init.d/mysqld
3、添加服务
#> chkconfig --add mysqld