-
下载mysql安装包
下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -
卸载系统自带的mysql
#检查mysql是否存在 [root@hadoop01 local]# rpm -qa | grep mysql mysql-libs-5.1.73-7.el6.x86_64 #卸载 [root@hadoop01 local]# rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64 [root@hadoop01 local]# find / -name mysql # 手动删除 数据库目录 [root@hadoop01 local]# rm -rf /var/lib/mysql/ # 手动删除 数据库配置文件 [root@hadoop01 local]# rm -rf /usr/share/mysql/
-
删除etc目录下的 数据库配置文件my.cnf
[root@hadoop01 local]# rm /etc/my.cnf rm: cannot remove `/etc/my.cnf': No such file or directory
-
检查mysql组和用户是否存在,如无创建
[root@hadoop01 local]# cat /etc/group | grep mysql [root@hadoop01 local]# cat /etc/passwd | grep mysql [root@hadoop01 local]#
-
创建mysql用户组
[root@hadoop01 local]# groupadd mysql #创建一个用户名为mysql的用户并加入mysql用户组 [root@hadoop01 local]# useradd -g mysql mysql [root@hadoop01 local]#
-
设置密码
[root@hadoop01 local]# passwd mysql Changing password for user mysql. New password: BAD PASSWORD: it is too simplistic/systematic BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully. [root@hadoop01 local]#
-
解压到指定文件夹下
[root@hadoop01 local]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz [root@hadoop01 local]# mv mysql-5.7.21-linux-glibc2.12-x86_64/ /usr/local/mysql/
-
更改所属的组和用户
[root@hadoop01 local]# chown -R mysql mysql/ [root@hadoop01 local]# chgrp -R mysql mysql/
-
创建数据库数据存储目录
[root@hadoop01 local]# mkdir /usr/local/mysql/data [root@hadoop01 mysql]# chown -R mysql:mysql data
-
新建配置文件my.cnf
[root@hadoop01 mysql]# vim /etc/my.cnf
在etc下新建配置文件my.cnf,并添加以下配置
[mysql] #设置mysql客户端默认字符集 default-character-set=utf8 [mysqld] skip-name-resolve #设置3306端口 port = 3306 #设置mysql的安装目录 basedir=/usr/local/mysql #设置mysql数据库的数据的存放目录 datadir=/usr/local/mysql/data #允许最大连接数 max_connections=200 #服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 #创建新表时将使用的默认存储引擎 default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M
-
安装和初始化
[root@hadoop01 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 2018-09-18 19:24:49 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2018-09-18 19:24:52 [WARNING] The bootstrap log isn't empty: 2018-09-18 19:24:52 [WARNING] 2018-09-18T11:24:49.123054Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead 2018-09-18T11:24:49.123633Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 2018-09-18T11:24:49.123640Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)
-
创建mysqld
[root@hadoop01 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld [root@hadoop01 mysql]#
-
将脚本文件设置成可执行文件
[root@hadoop01 mysql]# chown 777 /etc/my.cnf [root@hadoop01 mysql]# chmod a+x /etc/init.d/mysqld [root@hadoop01 mysql]# /etc/init.d/mysqld restart ERROR! MySQL server PID file could not be found! ERROR! MySQL server PID file could not be found! Starting MySQL.Logging to '/usr/local/mysql/data/hadoop01.err'. SUCCESS! [root@hadoop01 mysql]# killall mysqld [root@hadoop01 mysql]# /etc/init.d/mysqld start Starting MySQL. SUCCESS! [root@hadoop01 mysql]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS! [root@hadoop01 mysql]#
-
设置开机启动
[root@hadoop02 mysql]# chkconfig --list mysqld service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysqld') [root@hadoop01 mysql]# chkconfig --level 35 mysqld on [root@hadoop01 mysql]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@hadoop01 mysql]# chmod +x /etc/rc.d/init.d/mysqld [root@hadoop01 mysql]# chkconfig --add mysqld [root@hadoop01 mysql]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@hadoop01 mysql]# service mysqld status SUCCESS! MySQL running (3874) [root@hadoop01 mysql]#
-
配置环境变量
[root@hadoop01 mysql]# vim /etc/profile
#set mysql environment export MYSQL_HOME=/usr/local/mysql export PATH=$PATH:${MYSQL_HOME}/bin
[root@hadoop01 mysql]# source /etc/profile
-
查看初始密码
[root@hadoop01 mysql]# cat /root/.mysql_secret #Password set for user 'root@localhost' at 2018-09-18 19:24:49 gi?hydUfPhxD [root@hadoop01 mysql]#
-
修改密码
[root@hadoop01 mysql]# mysql -uroot -p Enter password: (输入 gi?hydUfPhxD) Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.23 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 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> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec)
-
远程连接授权
mysql> grant all privileges on *.* to root@"%" identified by "123456" with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
-
退出命令行界面
mysql> exit Bye
Linux下安装MySQL
最新推荐文章于 2022-06-29 16:50:00 发布