1.下载MySQL,http://dev.mysql.com/downloads/mysql/
选择适合你的版本下载即可。
2.将下载MySQL包上传到linux,进行解压:tar -xvf mysql.....
3.移动并修改文件名: mv /bigdata/mysql-8.0.18-linux-glibc2.12-x86_64.tar /usr/local/mysql
4.新建mysql用户、组及目录:groupadd mysql;useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
5.创建数据仓库目录:mkdir /data/mysql;
6.改变目录属有者:chown -R mysql .;chgrp -R mysql .;chown -R mysql /data/mysql;【注:分号前的' .'】
7.初始化:① bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql 【注意你的参数值】
此处需要注意记录生成的临时密码,如上文结尾处的: o9dQXD_R,g&w
② bin/mysql_ssl_rsa_setup --datadir=/data/mysql
8.修改系统配置文件:
① cp mysql.server /etc/init.d/mysql 【mysql.server 在你mysql_home的support-files目录中】
vim /etc/init.d/mysql
basedir=/usr/local/mysql
datadir=/data/mysql
② vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/
datadir=/data/mysql/
socket=/data/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
log-error=/usr/local/mysql/mysqld.log
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
character_set_server=utf8
init_connect='SET NAMES utf8'
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
9.启动: /etc/init.d/mysql start
/etc/init.d/mysql start
10.登陆:
mysql -hlocalhost -uroot -p
输入:第七步时候生成的临时密码 o9dQXD_R,g&w
输入完后无问题直接进入,而我在此报错。。。
①错误1
解决方式:ln -s /data/mysql/mysql.sock /tmp/mysql.sock 【注:/data/mysql/mysql.sock文件地址根据实际情况填写】
② 错误2
Starting MySQL.The server quit without updating PID file (/data/mysql//vm10-38-248-204.ksc.com.pid). [失败]
解决方式:配置 vi /etc/my.cnf
11.登陆到mysql第一件事就是修改临时密码,不然你操作任何命令,都是报错:
修改密码:alter user 'root'@'localhost' identified by '123456';
12.添加系统路径
# vim /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
13.设置系统命令,不然无法使用service mysqld status
①find / -name mysql.server
②cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
14.mysql服务设置远程连接 解决1251 client does not support ..问题
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'newpassword';
附加:
Linux杀掉MySQL进程(关键词:Linux/MySQL/杀死进程/mysql/mysqld)
1.查看mysql程序对应的进程号使用命令:ps -e|grep mysql
2.杀死mysql进程使用命令:sudo kill -9 mysql的进程号
3.杀死mysqld进程使用命令:sudo killall mysqld
4.检查是否还有mysql进程存在使用命令:psps -e|grep mysql