前提:已解压mysql包改名后放于/usr/local/src
rpm -qa|grep mysql(有则删)
rpm -qa|grep mariadb(有则删)
rpm -e --nodeps 包全名
cd /usr/local/src/mysql/
mkdir data
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chown -R mysql:mysql /usr/local/src/mysql
./bin/mysqld --user=mysql --basedir=/usr/local/src/mysql --datadir=/usr/local/src/mysql/data --initialize(复制保存生成的密码)
vi /etc/my.cnf(以下若为空白则自行敲)
[mysqld]
port=3306
user=mysql
basedir=/usr/local/src/mysql
datadir=/usr/local/src/mysql/data
socket=/tmp/mysql.sock
character_set_server=utf8mb4
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/src/mysql/data/error.log
pid-file=/usr/local/src/mysql/data/mysqld.pid
tmpdir=/tmp
cp /usr/local/src/mysql/support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld(使用set nu显示行号)
46行 basedir=/usr/local/src/mysql
47行 datadir=/usr/lcoal/src/mysql/data
63行 mysqld_pid_file_path=/usr/local/src/mysql/data/mysqld.pid
service mysqld start
若报错没PID file
则
ps -ef|grep mysqld
pkill -9 mysqld
若仍报错,出现ACCESS denied...
则
vi /etc/my.cnf
在[mysqld]下加
skip-grant-tables
若还报错则先重启再操作
cd /usr/local/src/mysql/bin/
./mysql -u root -p
(会出现password:填之前保存的密码)
alter user 'root'@'localhost' identified by '1(要改的新密码)';
exit(退出);
vi /etc/profile
写在最后一行
export MYSQL_HOME=/usr/local/src/mysql
export PATH=$PATH:${MYSQL_HOME}/bin
source /etc/profile