码迷,mamicode.com
首页 > 数据库 > 详细

Linux 安装mysql总结

时间:2021-02-01 11:43:05      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ons   inux   --   mysql总结   implicit   五步   flush   table   temp   

第一步:mysql安装包准备

mysql官网下载地址:https://downloads.mysql.com/

第二步:将mysql安装包上传到服务器

这里上传的工具很多,就不再赘述(我用的winscp)

技术图片

第三步:解压

tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

第四步:cp或mv到/usr/local/目录下,并命名为mysql

注意:这里不建议使用拷贝(cp),因为文件大的话就会很慢

 mv mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql

第五步:创建mysql用户组和用户

groupadd mysql
useradd -r -g mysql mysql

第六步:创建mysql配置存放目录data

cd /usr/local/mysql
mkdir data

第七步:为mysql目录修改用户权限

chown -R mysql:mysql /usr/local/mysql/

第八步:将mysql初始化,并记录初始密码(Bo39?ed2h*W1)

cd msyql/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

会出现以下:

2021-01-30T03:51:20.337410Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-30T03:51:21.458335Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-01-30T03:51:21.659739Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-01-30T03:51:21.722351Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6a99bae9-62ae-11eb-8966-00163e175cc4.
2021-01-30T03:51:21.724337Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2021-01-30T03:51:22.941639Z 0 [Warning] CA certificate ca.pem is self signed.
2021-01-30T03:51:22.977097Z 1 [Note] A temporary password is generated for root@localhost: Bo39?ed2h*W1

第九步:配置mysql(my.cnf)

vim /etc/my.cnf

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#skip-grant-tables
port = 3306
pid-file = /usr/local/mysql/data/mysql.pid
socket = /usr/local/mysql/data/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default_authentication_plugin = mysql_native_password

第十步:加入开机自启

cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql
chmod  +x /etc/init.d/mysql   //添加可执行权限
chkconfig --add mysql  // 添加开机自启
chkconfig --list  //查看自启是否添加成功

技术图片

第十一步:配置环境变量

vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
source /etc/profile

第十二步:启动mysql

systemctl restart mysql

第十三步:登录mysql

mysql -u root -pBo39?ed2h*W1 //初始化密码

会出现以下错误(说是要改一下/tmp/mysql.sock目录):
技术图片

vim /etc/my.cnf
socket = /tmp/mysql.sock
systemctl restart mysql //再重启服务

再次登录:(mysql -u root -pBo39?ed2h*W1)
技术图片
修改密码

alter user ‘root‘@‘localhost‘ identified with mysql_native_password by ‘123456‘;
或 set password for root@localhost= password(‘123456’);
flush privileges;

技术图片

Linux 安装mysql总结

标签:ons   inux   --   mysql总结   implicit   五步   flush   table   temp   

原文地址:https://www.cnblogs.com/songwp/p/14348771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!