# 下载 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz # 解压 tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/jdy # 进入安装目录 cd /usr/local/jdy # 修改名称 mv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql #(bash: mysql: command not found...) #原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下, #当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。 #首先得知道mysql命令或mysqladmin命令的完整路径,比如mysql的路径是: #/usr/local/mysql/bin/mysql ,我们则可以这样执行命令: ln -s /usr/local/jdy/mysql/bin/mysql /usr/bin
groupadd mysql
useradd -g mysql -r -s /sbin/nologin -M -d /data/mysqldata mysql
#给用户赋予文件权限 chown -R mysql:mysql /usr/local/jdy/mysql #新建数据目录 mkdir -p /data/mysqldata #给用户赋予权限 chmod -R 770 /data/mysqldata #给用户赋予权限 chown -R mysql:mysql /data/mysqldata
cd /usr/local/jdy/mysql
./bin/mysqld --user=mysql --basedir=/usr/local/jdy/mysql --datadir=/data/mysqldata --initialize
cp support-files/mysql.server /etc/init.d/mysqld ldconfig # 配置环境变量 echo "export MYSQL_HOME=/usr/local/jdy/mysql" >> /etc/profile echo "export PATH=$PATH:$MYSQL_HOME/bin" >> /etc/profile # 环境变量生效 source /etc/profile chkconfig mysqld on vim /etc/my.cnf
my.cnf文件
[mysqld]
#安装目录 basedir=/usr/local/jdy/mysql
#数据存放目录 datadir=/data/mysqldata socket=/tmp/mysql.sock symbolic-links=0 user=mysql server_id=1 port=3306 [mysqld_safe] log-error=/data/mysqldata/mariadb.log pid-file=/data/mysqldata/mariadb.pid !includedir /etc/my.cnf.d
#启动mysql service mysql start
set global validate_password_policy=0; set global validate_password_length=1;
[root@001 mysql]# mysql -uroot -p alter user 'root'@'localhost' identified by 'root'; mysql> FLUSH PRIVILEGES;
service iptables stop
chkconfig iptables off
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
授权完成要重新启动才会生效