前言:
现在看官们对“mysqldinstallmysql”大概比较讲究,各位老铁们都需要了解一些“mysqldinstallmysql”的相关内容。那么小编在网摘上收集了一些有关“mysqldinstallmysql””的相关资讯,希望咱们能喜欢,各位老铁们一起来了解一下吧!一、安装单实例
1、升级openssl
#查看版本openssl version#openssl 安装包 openssl-1.1.0j.tar.gz #下载地址 /usr/local/openssl-1.1.1./configmakemake install#受影响的文件夹#/usr/local/bin#/usr/local/include#/usr/local/lib#先查找 当前openssl的生效目录which openssl#设置软连接 路径:/usr/bin/opensslmv /usr/bin/openssl /usr/bin/openssl.oldln -s /usr/local/bin/openssl /usr/bin/opensslopenssl version#报错error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1CopyView Code
openssl升级
2、替换软件源
#替换软件源sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup# 粘贴的时候 :set paste 按下i时候 可直接粘贴#用完后需:set nopastesudo apt-get updatesudo apt-get upgradeCopyView Code
3、root 用户ssh远程登录
#新装的系统,首先设置root密码sudo passwd#编辑 SSH 的文件,将PermitRootLogin 的值改为yes$ vim /etc/ssh/sshd_config#重启ssh服务sudo service ssh restart
4、mysql需要安装的包
#1.环境准备apt-get install make cmake gcc g++ bison libncurses5-dev build-essential#2.添加用户和组groupadd mysqluseradd -d /home/mysql -g mysql -m mysql#查看mysqlid mysql#创建密码 sudo passwd mysql#useradd#-c:加上备注文字,备注文字保存在passwd的备注栏中。#-d:指定用户登入时的主目录,替换系统默认值/home/<用户名>#-D:变更预设值。#-e:指定账号的失效日期,日期格式为MM/DD/YY,例如06/30/12。缺省表示永久有效。#-f:指定在密码过期后多少天即关闭该账号。如果为0账号立即被停用;如果为-1则账号一直可用。默认值为-1.#-g:指定用户所属的群组。值可以使组名也可以是GID。用户组必须已经存在的,期默认值为100,即users。#-G:指定用户所属的附加群组。#-m:自动建立用户的登入目录。#-M:不要自动建立用户的登入目录。#-n:取消建立以用户名称为名的群组。#-r:建立系统账号。#-s:指定用户登入后所使用的shell。默认值为/bin/bash。#-u:指定用户ID号。该值在系统中必须是唯一的。0~499默认是保留给系统用户账号使用的,所以该值必须大于499。#3.cmakecmake \-DCMAKE_INSTALL_PREFIX=/u01/my3306 \-DINSTALL_DATADIR=/u01/my3306/data \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DEXTRA_CHARSETS=all \-DWITH_SSL=yes \-DWITH_EMBEDDED_SERVER=1 \-DENABLED_LOCAL_INFILE=1 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DMYSQL_UNIX_ADDR=/u01/my3306/run/mysql.sock \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DSYSCONFDIR=/etc \-DWITH_BOOST=boost \-DWITH_READLINE=on#4.make#5.make install#6.目录重新授权chown -R mysql:mysql /u01/my3306chmod 755 -R /u01/my3306#7.复制my.cnf 初始化./mysqld --defaults-file=/u01/my3306/my.cnf --initialize --datadir=/u01/my330 6/data --user=mysql./mysqld --defaults-file=/u01/my3306/my.cnf --initialize-insecure --datadir=/u01/my3306/data --user=mysql#--initialize 会生成一个随机密码,而 -–initialize-insecure 不会生成密码,在MySQL安全配置向导mysql_secure_installation设置密码时,可自由选择 mysql 密码等级。#--datadir目标目录下不能有数据文件。--重新初始化 需删除data和log的所有文件rm -fr /u01/my3306/log/binlog/*rm -fr /u01/my3306/log/iblog/*rm -fr /u01/my3306/data/*#8.启动mysql./mysqld_safe --defaults-file=/u01/my3306/my.cnf --user=mysql 	.配置安全向导#
5、navicate 连接虚拟机mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'rootroot' WITH GRANT OPTION;FLUSH PRIVILEGES;
6、安装mysql utilities
==最好源码安装==
# wget -c unzip mysql-utilities-1.5.3.zip# cd mysql-utilities-1.5.3# python ./setup.py build# python ./setup.py install二、安装双实例
1、目录结构
#mysql@Fight:~$ tree /home/mysql/新建脚本文件.├── m6├── m7├── shutdown3306.sh├── shutdown3307.sh├── start3306.sh└── start3307.sh#mysql@Fight:/u01$ tree -L 1 根目录 /u01 其中tmp 为空用作安装时的临时目录 mysql程序放在svr.├── conf├── logs├── mydata├── mysql-5.7.24├── mysql-boost-5.7.24.tar.gz├── svr└── tmp#mysql@Fight:/u01/conf$ ls mysql#mysql@Fight:/u01/conf$ cd mysql#mysql@Fight:/u01/conf/mysql$ tree.├── my3306.cnf└── my3307.cnf#mysql@Fight:/u01/logs$ tree.├── my3306│ ├── binlog│ │ ├── binlog.000001│ │ ├── binlog.000002│ │ ├── binlog.000003│ │ ├── binlog.000004│ │ └── binlog.index│ ├── error3306.log│ ├── iblog│ │ ├── ib_buffer_pool│ │ ├── ibdata1│ │ ├── ibdata2│ │ ├── ib_logfile0│ │ ├── ib_logfile1│ │ ├── ib_logfile2│ │ ├── ib_logfile3│ │ └── ibtmp1│ └── slow3306.log└── my3307 ├── binlog │ ├── mysql-bin.000001 │ ├── mysql-bin.000002 │ ├── mysql-bin.000003 │ ├── mysql-bin.000004 │ └── mysql-bin.index ├── error3307.log ├── iblog │ ├── ib_buffer_pool │ ├── ibdata1 │ ├── ibdata2 │ ├── ib_logfile0 │ ├── ib_logfile1 │ ├── ib_logfile2 │ ├── ib_logfile3 │ └── ibtmp1 └── slow3307.log #mysql@Fight:/u01/mydata$ tree -L 2.├── my3306│ ├── auto.cnf│ ├── ca-key.pem│ ├── ca.pem│ ├── client-cert.pem│ ├── client-key.pem│ ├── mysql│ ├── mysqld.pid│ ├── performance_schema│ ├── private_key.pem│ ├── public_key.pem│ ├── server-cert.pem│ ├── server-key.pem│ └── sys└── my3307 ├── auto.cnf ├── ca-key.pem ├── ca.pem ├── client-cert.pem ├── client-key.pem ├── mysql ├── mysqld.pid ├── performance_schema ├── private_key.pem ├── public_key.pem ├── server-cert.pem ├── server-key.pem └── sys#mysql@Fight:/u01/svr$ tree -L 2.└── mysql5.7 ├── bin ├── COPYING ├── COPYING-test ├── docs ├── include ├── lib ├── man ├── mysql-test ├── README ├── README-test ├── share └── support-files#mysql@Fight:/u01/tmp$ ls#mysql@Fight:/u01/tmp$ tree
2、脚本语句
m6 ./m6mysql --socket=/tmp/mysql3306.sock --port=3306m7 ./m6mysql --socket=/tmp/mysql3307.sock --port=3307start3306.sh sh start3306.shmysqld_safe --defaults-file=/u01/conf/mysql/my3306.cnf --user=mysql &start3307.sh sh start3307.sh -mysqld_safe --defaults-file=/u01/conf/mysql/my3307.cnf --user=mysql &`shutdown3306.sh sh shutdown3306.shmysqladmin --socket=/tmp/mysql3306.sock --port=3306 shutdown &shutdown3307.sh sh shutdown3307.shmysqladmin --socket=/tmp/mysql3307.sock --port=3307 shutdown &赋可执行权限chmod 777 -R m6,m7,start3306.sh,start3307.sh,shutdown3306.sh,shutdown3307.sh
3、修改环境变量
#配置环境变量vim .profile#修改后#mysql@Fight:~$ cat .profile# ~/.profile: executed by the command interpreter for login shells.# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login# exists.# see /usr/share/doc/bash/examples/startup-files for examples.# the files are located in the bash-doc package.# the default umask is set in /etc/profile; for setting the umask# for ssh logins, install and configure the libpam-umask package.#umask 022# if running bashif [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fifi# set PATH so it includes user's private bin directoriesPATH="$HOME/bin:$HOME/.local/bin:$PATH:/u01/svr/mysql5.7/bin"
4、编译
#1. cmake cmake \-DCMAKE_INSTALL_PREFIX=/u01/svr/mysql5.7 \-DINSTALL_DATADIR=/u01/svr/mysql5.7/data \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DEXTRA_CHARSETS=all \-DWITH_SSL=yes \-DWITH_EMBEDDED_SERVER=1 \-DENABLED_LOCAL_INFILE=1 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DMYSQL_UNIX_ADDR=/u01/svr/mysql5.7/run/mysql.sock \-DENABLED_LOCAL_INFILE=1 \-DSYSCONFDIR=/etc \-DWITH_BOOST=boost \-DWITH_READLINE=on#2. make#3. make install
5、初始化
#初始化./mysqld --defaults-file=/u01/conf/mysql/my3306.cnf --initialize-insecure --datadir=/u01/mydata/my3306 --user=mysql./mysqld --defaults-file=/u01/conf/mysql/my3307.cnf --initialize-insecure --datadir=/u01/mydata/my3307 --user=mysql
6、启动
#启动./mysqld_safe --defaults-file=/u01/conf/mysql/my3306.cnf --user=mysql &./mysqld_safe --defaults-file=/u01/conf/mysql/my3307.cnf --user=mysql &
7、进入
#mysql --socket=/tmp/mysql3306.sock --port=3306./m6#mysql --socket=/tmp/mysql3307.sock --port=3306./m7#远程连接./m6#进入mysqlset password for root@localhost = password('rootroot');#还不行GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'rootroot' WITH GRANT OPTION;FLUSH PRIVILEGES;
8、配置数据库密码安全性
#3306mysql_secure_installation -uroot -prootroot --socket=/tmp/mysql3306.sock#3307mysql_secure_installation -uroot -prootroot --socket=/tmp/mysql3307.sock#取消密码验证三、安装5.6
升级OpenSSL
#Ubuntu 16.04.5 默认版本 OpenSSL 1.0.2g 1 Mar 2016 需更换为OpenSSL 1.0.2r 26 Feb 2019#1、解压tar -zxvf openssl-1.0.2r.tar.gzcd openssl-1.0.2r./config --prefix=/usr/local --openssldir=/usr/local/opensslmv /usr/bin/openssl /usr/bin/openssl.oldln -s /usr/local/bin/openssl /usr/bin/openssl#2、查看版本 openssl version#解决的问题#In function ‘int my_aes_decrypt(const unsigned char*, uint32, unsigned char*, const #unsigned char*, uint32, my_aes_opmode, const unsigned char*)’:#/u01/mysql-5.6.43/mysys_ssl/my_aes_openssl.cc:148:18: error: aggregate ‘EVP_CIPHER_CTX ctx’ has incomplete type and cannot be defined# EVP_CIPHER_CTX ctx;#3、新问题#[ 82%] Linking CXX shared library libmysqlclient.so#/usr/local/lib/libssl.a: error adding symbols: Bad value#基本原理#我们都知道在生成一个动态库时需要指定-fPIC,这是创建动态库所要求的,共享库被加载是在内存中的位置是不固定的,是一个相对的位置。#那么在生成静态库时通常不指定-fPIC, 可是在64bit编译使用静态库就会提示需要-fPIC重新编译该库。#由于openssl编译静态库时,没有使用-fPIC选项,使得编译出来的静态库没有重定位能力。#这样在64bit机器上编译出来的静态库如果不指定-fPIC选项几乎全部不能使用。#因此需要重新加上-fPIC从新编译openssl#4、删除openssl-1.0.2l,重新解压。./config -fPIC --prefix=/usr/local --openssldir=/usr/local/opensslmake dependmake install
1、复制脚本并修改端口号3308
cp m6 m8cp shutdown3306.sh shutdown3308.shcp start3306.sh start3308.sh#赋权限chmod 777 m8chmod 777 shutdown3308.shchmod 777 start3308.sh
2、创建目录
mkdir -p /u01/logs/my3308/iblogmkdir -p /u01/logs/my3308/binlogmkdir -p /u01/logs/my3308/relaylog #主从复制需要mkdir -p /u01/mydata/my3308#mkdir -p /u01/mydata/my3308/tmp 从机需要mkdir -p /u01/conf/mysqlmkdir -p /u01/svr/mysql5.6mkdir -p /u01/tmp
3、修改配置文件my3308.cnf
#修改权限chown -R mysql:mysql /u01/conf/mysql/my3308.cnfchmod 755 my3308.cnf
4、编译
#1. cmake cmake \-DCMAKE_INSTALL_PREFIX=/u01/svr/mysql5.6 \-DINSTALL_DATADIR=/u01/svr/mysql5.6/data \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DEXTRA_CHARSETS=all \-DWITH_SSL=system \-DWITH_EMBEDDED_SERVER=1 \-DENABLED_LOCAL_INFILE=1 \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DMYSQL_UNIX_ADDR=/u01/svr/mysql5.6/run/mysql.sock \-DENABLED_LOCAL_INFILE=1 \-DSYSCONFDIR=/etc #5.6不需要-DWITH_BOOST=boost \#2. make 报错#清楚make 缓存#make clean#rm CMakeCache.txt#3. make install
5、初始化
#cd /u01/svr/mysql5.6/scripts./mysql_install_db --defaults-file=/u01/conf/mysql/my3308.cnf --datadir=/u01/mydata/my3308 --user=mysql#报错#FATAL ERROR: Could not find ./bin/my_print_defaults#bin目录有这个文件,#. 当前目录 ./bin 当前目录下的bin文件夹 ./scripts/mysql_install_db --defaults-file=/u01/conf/mysql/my3308.cnf --datadir=/u01/mydata/my3308 --user=mysql
6、启动
mysqld_safe --defaults-file=/u01/conf/mysql/my3308.cnf --user=mysql &四、尝试
1、密码修改
#远程连接密码GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'rootroot' WITH GRANT OPTION;FLUSH PRIVILEGES;#dos 数据库登录密码set password for root@localhost = password('rootroot');flush privileges;
2、validate_password
#最初 配置安全向导mysql_security_install -uroot -prootroot --socket=/tmp/mysql3307.sock #.so 路径 /u01/svr/mysql5.7/lib/plugin/install plugin validate_password soname 'validate_password.so';#禁用 不区分大小写validate_password=off validate-password=OFF#查看插件列表show plugins;#查看系统中所有的表,可以查看那些Plugin是可以卸载的select *from information_schema.`PLUGINS`;#插件注册表#如果使用该--skip-grant-tables选项启动服务器 ,则不会查询该mysql.plugin表,也不会加载其中列出的插件。select *from mysql.`plugin`;#卸载插件uninstall plugin validate_password;#1.内置插件不能卸载 information_schema.library 为null的#2.select t.load_option from information_schema t; value为force_plus_permanent#禁止在运行的时候卸载插件#取消root用户登录时的密码set password for root@localhost=password('');
3、mysqld_multi¶
#不准,两个实例明明结束了,仍然显示正在运行#j/etc/my.cnf 配置文件出错mysqldadmin的路径配置了
4、查看my.cnf配置文件查找顺序¶
mysqld --verbose --help|grep my.cnf#mysql@Fight:~$ mysqld --verbose --help|grep my.cnf#/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf# my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default
后面会分享更多运维方面的内容,感兴趣的朋友可以关注一下~