yum install wget
yum install perl perl-devel
cd /usr/local/src
wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
tar zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.40-linux-glibc2.12-x86_64 /usr/local/mysql
useradd -s /sbin/nologin mysql创建存放数据的目录:
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql/
执行:
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql配置文件:
cp my.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vim /etc/init.d/mysqld ,在配置里找到 basedir datadir 进行设置
basedir=/usr/local/mysql
datadir=/data/mysql
chkconfig --add mysqld
chkconfig mysqld on管理mysqld服务:
systemctl status mysqld
systemctl stop mysqld
systemctl start mysqld在/etc/profile 添加信息:
vim /etc/profile
export PATH=$PATH:'/usr/local/mysql/bin'
source /etc/profile
设置mysql密码:
mysqladmin -uroot password '123456'
清除历史记录:
history -c>systemctl stop mysqld
>mysqld_safe --skip-grant-tables &
输入 mysql -uroot -p 回车进入
>use mysql;
> update user set password=PASSWORD("www.code306.cn")where user="root"; #更改密码为 newpass
> flush privileges; #更新权限 > quit #退出
>service mysqld restart
>mysql -uroot -pnewpass #新密码进入
修改MySQL密码:
mysql -u root
mysql> use mysql;
mysql>
UPDATE
user
SET
Password
=
PASSWORD
(
'newpass'
)
WHERE
user
=
'root'
;
mysql> FLUSH
PRIVILEGES
;
MySQL允许远程登录:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;
MySQL忘记密码:
1.用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf
2.在[mysqld]下添加skip-grant-tables,然后保存并退出
3.重启mysql服务
4.重启以后,执行mysql命令进入mysql命令行
mysql>
UPDATE
user
SET
Password
=
PASSWORD
(
'newpass'
)
WHERE
user
=
'root'
;
mysql> FLUSH
PRIVILEGES
;