linux安装mysql

1、下载

官网:  https://dev.mysql.com/downloads/mysql/

2、安装包上传至Linux服务器

3、解压

tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar  (得到三个压缩包)

 

tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz (选择这个继续解压)

4、重命名并移动到合适的路径

重命名 :mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql

移动:mv mysql /usr/local

 

5、添加用户组

切换路径: cd /usr/local

添加用户和用户组:groupadd mysql

                                 useradd -r -g mysql mysql

 

6、授权

cd mysql

chown -R mysql:mysql ./

 

7、在/usr/local/mysql下创建data文件夹

mkdir data

8、

yum -y install numactl

yum install libaio-devel.x86_64

9、初始化数据库,自动生成密码

 

这里要注意,mysql8之后,必须在初始化时设置大小写

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

 

10、修改/usr/local/mysql 当前目录的用户

chown -R root:root ./

chown -R mysql:mysql data

 

11、复制my-default.cnf这个文件到etc/my.cnf去

cd support-files/

touch my-default.cnf

chmod 777 ./my-default.cnf

cd ../

cp support-files/my-default.cnf /etc/my.cnf

 

12、完了之后配置my.cnf

vim /etc/my.cnf

[mysqld]
 
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
 
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
 
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
port = 5186
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 
 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

如果后期mysql运行报错,可以直接到log-error = /usr/local/mysql/data/error.log目录下直接查看错误日志

命令:cat /usr/local/mysql/data/error.log

 

13、开机自启,进入/usr/local/mysql/support-files进行设置

cd support-files/
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql

 

14、注册服务

chkconfig --add mysql

 

15、etc/ld.so.conf要配置路径,不然报错

vim /etc/ld.so.conf 添加如下内容:

/usr/local/mysql/lib

16、配置环境变量

 vim /etc/profile
添加如下内容:
#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
 然后退出执行
source /etc/profile
 
17登录 需要用到上面的生成的密码

 service mysql start

mysql -uroot -p

18 修改密码

alter user 'root'@'localhost' identified by '123456';

19 远程连接  修改host

mysql -u root -p

use mysq;

select host from user where user='root';

update user set host = '%' where user ='root'将Host设置为通配符%。

Host设置了“%”后便可以允许远程访问。

执行flush privileges;­使配置立即生效。

 

20 、解决

Authentication plugin 'caching_sha2_password' cannot be loaded的错误。

 mysql -u root -p

   ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;   #修改加密规则 

   ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';   #更新一下用户的密码 

FLUSH PRIVILEGES;   #刷新权限 

alter user 'root'@'localhost' identified by '111111';

 

21、数据库kill -9  重启报错  

我采用下面的方法,竟然可以启动MySQL,但是又引发了其他的无法解决的error
##################################    方法如下    ##############################
按照网址:http://www.justin.my/2012/03/starting-mysql-error-the-server-quit-without-updating-pid-file/
竟然可以启动MySQL服务,如下:
***@***-VirtualBox:/etc$ sudo mv /etc/my.cnf /etc/my.cnf.old
***@***-VirtualBox:/etc$ sudo /etc/init.d/mysql.server start

 

posted @ 2019-11-27 20:35  跃小云  阅读(252)  评论(0编辑  收藏  举报