在CentOS上配置MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql

# Postinstallation setup
cd /usr/local/mysql
sudo mkdir mysql-files
sudo chown mysql:mysql mysql-files
sudo chmod 777 mysql-files
sudo bin/mysqld --initialize --user=mysql

sudo mkdir /var/run/mariadb
sudo mkdir /var/log/mariadb
sudo chown mysql:mysql
sudo touch /var/log/mariadb/mariadb.log
sudo chmod 777 /var/log/mariadb/mariadb.log
sudo chmod 777 /var/run/mariadb/
sudo chmod 777 /var/log/mariadb/
sudo chmod 777 /var/lib/mysql


sudo bin/mysql_ssl_rsa_setup
sudo bin/mysqld_safe --user=mysql &
sudo bin/mysqld --user=mysql &
sudo vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin

如果mysqld_safe遇到错误
mysqld_safe mysqld from pid file /var/lib/mysql/mysqld.pid ended
sudo chmod 777 /var/log/mariadb/mariadb.log
chmod -R 777 /var/lib/mysql #这个是重点
如果在mysql -uroot -p 登录时,提示:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

初始密码设置

1
2
3
set password for root@localhost = password('密码');
grant all privileges on *.* to '对外用户名'@'%' identified by '对外密码';
flush privileges;