1、检查是否已经安装过mysql,若安装过,删除:
rpm -qa | grep mysql
whereis mysql
find / -name mysql
2、检查mysql用户组和用户是否存在,如果没有,则创建
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
groupadd mysql
useradd -r -g mysql mysql
3、下载安装包:
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
4、安装:
tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/
cd /usr/local/
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
记录日志最末尾位置root@localhost:后的字符串,此字符串为mysql管理员临时登录密码。
vi /etc/my.cnf
加入下面内容:
[mysqld]
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
5、启动
/usr/local/mysql/support-files/mysql.server start
添加软连接:
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
6、登录mysql,修改密码(密码为步骤4生成的临时密码)
mysql -u root -p
set password for root@localhost = password('yourpass');
开放远程连接
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
7、设置开机自动启动
1、将服务文件拷贝到init.d下,并重命名为mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
chmod +x /etc/init.d/mysqld
3、添加服务
chkconfig --add mysqld
4、显示服务列表
chkconfig --list
至此,安装MySQL初步完成。
有问题移步:https://www.jianshu.com/p/276d59cbc529
添加用户并授权:
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
例如:
CREATE USER 'javacui'@'localhost' IDENTIFIED BY '123456';
授权:
GRANT privileges ON databasename.tablename TO 'username'@'host';
privileges – 用户的操作权限,如SELECT , INSERT , UPDATE 等
例如:
GRANT SELECT, INSERT ON test.user TO 'javacui'@'%';
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
修改密码:
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
如果是当前登陆用户用
SET PASSWORD = PASSWORD("newpassword");
撤销用户权限:
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
DROP USER ‘username’@'host’;
操作后刷新:
flush privileges;