一、下载MySQL
通过wget进行下载:
[root@iZwz9ba9y5k8ij7xf2boohZ software]#wget https://downloads.mysql.com/archives/get/p/23/file/ \
mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
二、安装与配置
1、创建mysql用户和组
#创建MySQL用户
[root@iZwz9ba9y5k8ij7xf2boohZ software]#useradd mysql -s /sbin/nologin -M -g mysql
#创建MySQL组
[root@iZwz9ba9y5k8ij7xf2boohZ software]#groupadd mysql
2、解压
[root@iZwz9ba9y5k8ij7xf2boohZ software]#tar-xf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
3、安装
#1、重命名
[root@iZwz9ba9y5k8ij7xf2boohZ software]#mv mysql-8.0.13-linux-glibc2.12-x86_64 mysql
#2、拷贝到/usr/local下
[root@iZwz9ba9y5k8ij7xf2boohZ software]#mv mysql /usr/local/
#3、 进入到/usr/local/mysql目录下,进行授权
[root@iZwz9ba9y5k8ij7xf2boohZ mysql]#chown -R mysql:mysql ./
#4、初始化
[root@iZwz9ba9y5k8ij7xf2boohZ mysql]#./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
注意:
不需要提前创建好data目录,否则会出现[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting问题
会生成临时密码,记得保存
4、配置
my.cnf
进入到/usr/local/mysql/support-files目录中:
#1、创建my-default.cnf文件
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]#touch my-default.cnf
#2、赋予文件权限
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]#chmod 777 my-default.cnf
#3、将其覆盖/etc/my.cnf
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]#cp my-default.cnf /etc/my.cnf
#4、写入对应配置
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]#vim /etc/my.cnf
vim /etc/my.cnf
[mysqld]#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
socket= /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir= /tmp
port= 5186
#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
启动配置
#启动文件拷贝
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]#cp mysql.server /etc/init.d/mysql#服务可执行权限
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]#chmod +x /etc/init.d/mysql
5、启动MySQL
#启动MySQL
[root@iZwz9ba9y5k8ij7xf2boohZ support-files]#/etc/init.d/mysql start
Starting MySQL.Logging to '/usr/local/mysql/data/error.log'.
. [ OK ]#查看
[root@iZwz9ba9y5k8ij7xf2boohZ ~]#netstat -tunlp|grep 5186
tcp6 0 0 :::5186 :::* LISTEN 7249/mysqld
6、客户端环境变量配置
[root@iZwz9ba9y5k8ij7xf2boohZ bin]#echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
[root@iZwz9ba9y5k8ij7xf2boohZ bin]#source /etc/profile
7、修改密码
首先使用临时生成的密码进行登录,然后修改密码:
#登录
[root@iZwz9ba9y5k8ij7xf2boohZ bin]#mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ;or\g.
Your MySQL connection idis 8Server version:8.0.13
#修改密码
mysql> alter user 'root'@'localhost' identified by '********';
Query OK, 0 rows affected (0.08 sec)
此时,可以退出,再使用新密码进行登录了。
8、远程登录
mysql> select host,user frommysql.user;+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00sec)
mysql> update mysql.user set host='%' where user='root';
Query OK,1 row affected (0.01sec)
Rows matched:1 Changed: 1Warnings: 0
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
参考:https://blog.csdn.net/atongmu2017/article/details/90610444