MYSQL和MariaDB二进制安装
二进制安装mysql5.7.30
1.删除系统自带MySQL和系统账号
rpm -ql mysql
rpm -ql mariadb
yum remove mariadb -y
userdel -r mysql
2.准备用户和数据库目录
groupadd -r -g 306 mysql
mkdir /data/mysql -p
useradd -r -g 306 -u 306 -d /data/mysql/ mysql
chown mysql:mysql /data/mysql/
3.安装MySQL
cd /opt/
tar zvxf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
ln -sv mysql-5.7.30-linux-glibc2.12-x86_64 mysql
chown -R root:root /usr/local/mysql
4.修改配置文件
[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
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
[mysqld_safe]
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
5.安装依赖包(可能需要)
yum install libaio numactl-libs
6.配置变量数据库初始化及开机启动
echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
ln -s /usr/local/mysql/bin/* /usr/bin/
mysqld --initialize --user=mysql --datadir=/data/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
ln -s /data/mysql/mysql.sock /tmp/mysql.sock
service mysqld start
ss -nlt
7.重置密码
mysqladmin -uroot -pFavr6F1X3n+t password magedu
8.如果不成功进入安全模式重置密码
mysqld_safe --skip-grant-tables &
199 20200818-103716:history
mysql> use mysql;
Database changed
9.手动update修改密码
mysql> update mysql.user set authentication_string=password("123456") where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
安装包在/opt下
[16:19:47 root@localhost ~]#cat mysql_install.sh
#!/bin/bash
DIR=`pwd`
NAME="mysql-5.6.48-linux-glibc2.12-x86_64"
FULL_NAME=/opt/${NAME}.tar.gz
DATA_DIR="/data/mysql"
yum install libncurses*
if [ -f ${FULL_NAME} ];then
echo "安装文件存在"
else
echo "安装文件不存在"
exit 3
fi
if [ -e /usr/local/mysql ];then
echo "MySQL已经安装"
exit 3
else
tar xvf ${FULL_NAME} -C /usr/local/
ln -sv /usr/local/${NAME} /usr/local/mysql
if id mysql;then
echo "MySQL 用户已存在,跳过创建过程"
else
useradd -r -s /sbin/nologin mysql
fi
if id mysql;then
chown -R mysql:mysql /usr/local/mysql/
if [ ! -d /data/mysql ];then
mkdir -pv /data/mysql && chown -R mysql:mysql /data
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
cp /usr/local/${NAME}/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
cp ${DIR}/my.cnf /etc/my.cnf
ln -sv /usr/local/mysql/bin/mysql /usr/bin/mysql
/etc/init.d/mysqld start
chkconfig --add mysqld
else
echo "MySQL数据目录已经存在"
exit 3
fi
fi
fi
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
ln: failed to create symbolic link '/usr/bin/mysql': File exists
Starting MySQL. SUCCESS!
[17:13:43 root@localhost ~]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[17:15:24 root@localhost ~]#. /etc/profile.d/mysql.sh
[16:38:09 root@localhost ~]#cat /etc/my.cnf
[mysqld]
socket=/data/mysql/mysql.sock
user=mysql
symbolic-links=0
datadir=/data/mysql
innodb_file_per_table=1
[client]
port=3306
socket=/data/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/tmp/mysql.sock
二进制安装mariadb-10.5.5
yum remove mariadb -y
userdel -r mysql
mkdir -pv /data/mysql
groupadd -r -g 306 mysql
useradd -r -g 306 -u 306 -d /data/mysql/ mysql
chown mysql:mysql /data/mysql/
cd /opt/
tar zvxf mariadb-10.5.5-linux-systemd-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -s mariadb-10.5.5-linux-systemd-x86_64 mysql
chown root:root /usr/local/mysql/
vim /etc/my.cnf
./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
cp ./support-files/systemd/mariadb.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl enable --now mariadb.service
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysqld.sh
. /etc/profile.d/mysqld.sh
/usr/local/mysql/bin/mysql_secure_installation
第一步是说
ln -s /data/mysql/mysql.sock /tmp/mysql.sock
mysql -uroot -p

浙公网安备 33010602011771号