在CentOS上配置MySQL 发表于 2019-04-20 | 更新于 2019-04-27 | 分类于 Linux 123456789101112131415161718192021222324252627282930313233sudo groupadd mysqlsudo useradd -r -g mysql -s /bin/false mysql# Postinstallation setupcd /usr/local/mysqlsudo mkdir mysql-filessudo chown mysql:mysql mysql-filessudo chmod 777 mysql-filessudo bin/mysqld --initialize --user=mysql sudo mkdir /var/run/mariadbsudo mkdir /var/log/mariadbsudo chown mysql:mysqlsudo touch /var/log/mariadb/mariadb.logsudo chmod 777 /var/log/mariadb/mariadb.logsudo 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_profileexport PATH=$PATH:/usr/local/mysql/bin 如果mysqld_safe遇到错误mysqld_safe mysqld from pid file /var/lib/mysql/mysqld.pid endedsudo chmod 777 /var/log/mariadb/mariadb.logchmod -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 初始密码设置 123set password for root@localhost = password('密码');grant all privileges on *.* to '对外用户名'@'%' identified by '对外密码';flush privileges;