centos上Mysql安装及配置

1.添加mysql用户:

groupadd mysql
useradd -r -g mysql mysql

2.解压mysql:

tar zxf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-5.6.51-linux-glibc2.12-x86_64/ mysql
chown -R mysql:mysql mysql/

3.创建mysql实例数据目录:

mkdir /data/mysql/3306/data -p
chown -R mysql:mysql /data/mysql

4.编辑配置文件

cp /usr/local/mysql/support-files/my-default.cnf /data/mysql/3306/my.cnf
vi /data/mysql/3306/my.cnf
#复制下文到配置文件
[client]
password = 123456
port = 3306
socket = /data/mysql/3306/mysql_3306.sock
default-character-set=utf8

[mysqld]
port = 3306
socket = /data/mysql/3306/mysql_3306.sock
pid-file = /data/mysql/3306/mysql.pid
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/3306/data
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
max_connections=1000

5.添加环境变量:

#修改数据目录的属主、属组
chown -R mysql:mysql /data/mysql/

vim /etc/profile
#添加这两行到配置文件
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
#加载配置文件
source /etc/profile

6.初始化:
安装autoconf,不然会报错:

FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
Data::Dumper

yum install autoconf -y

创建需要目录和文件,并设置属主和属组,不然会报错:

mysqld_safe Directory ‘/var/lib/mysql’ for UNIX socket file don’t exists.
mysqld_safe error: log-error set to ‘/var/log/mariadb/mariadb.log’, however file don’t exists. Create writable for user ‘mysql’.

mkdir   /var/log/mariadb/
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql   /var/log/mariadb/
mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql

准备完毕,初始化

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --user=mysql
chown -R mysql:mysql /data/mysql/

7.mysql启动实例:

mysqld_safe --defaults-file=/data/mysql/3306/my.cnf 2>&1 > /dev/null &

8.查看实例:

netstat -tulpn | grep -i mysql
或
ps -ef | grep mysql

9.登录实例:

#这里mysql的root用户并没有设置密码,密码提示直接敲 Enter即可
mysql -uroot -p -S /data/mysql/3306/mysql_3306.sock
Enter password: 直接回车

10.关闭实例:

#这里mysql的root用户并没有设置密码,密码提示直接敲 Enter即可
mysqladmin -uroot -p -S /data/mysql/3306/mysql_3306.sock shutdown
Enter password: 直接回车

你可能感兴趣的:(mysql,centos,linux)