下载解压mysql的压缩包,文件夹改名mysql
tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz #解压安装包
mv mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz mysql #修改文件夹名称
创建用户和用户组
groupadd mysql #创建组
useradd -g mysql mysql #创建用户
创建data文件存放数据,并授权全部文件
mkdir /mysql解压文件夹/data #创建data文件夹,用于存放数据库表
chown -r -g mysql:mysql /mysql解压文件夹 #修改权限
初始化数据库,并记录生成的随机密码
bin/mysqld --initialize --user=mysql --basedir=/opt/mysql8.0 --datadir=/opt/mysql8.0/data #初始化MySQL,会生成默认密码,用于第一次登陆
创建my.cnf配置文件文件配置MySQL
因为mysql启动会自动寻找/etc/my.cnf配置文件,所以把配置文件放到/etc目录下,命名为my.cnf
[mysqld]
#Rove 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 = /opt/mysql
datadir = /opt/mysql/data
socket = /tmp/mysql.sock
log-error = /opt/mysql/data/error.log
pid-file = /opt/mysql/data/mysql.pid
tmpdir = /tmp
port = 3306
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
设置开机自启动
# cd /mysql解压目录/support-files/
# cp mysql.server /etc/init.d/mysql
# chmod +x /etc/init.d/mysql
注册服务
chkconfig --add mysql
etc/ld.so.conf要配置路径
/mysql安装目录全路径/lib
配置环境变量
export PATH=$PATH:/mysql解压全路径/bin:/mysql解压全路径/lib
启动MySQL,登陆,输入之前随机生成的密码
service mysql start #启动mysql
mysql -uroot -p #登陆
然后输入之前初始化自动生成的密码登陆
修改root密码
alter user 'root'@'localhost' identified by '你的新的root账户密码';