Linux下MySQL安装

Posted DBA萌新

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下MySQL安装相关的知识,希望对你有一定的参考价值。

博主邮箱[email protected]   qq:1102471911
1
//获得以下所需的源代码包(文末附有安装包),并存放在/usr/local/src 2 //mysql相关: 3 boost_1_59_0.tar.gz cmake-3.6.2.tar.gz mysql-5.7.16.tar.gz 4 5 //安装cmake前的依赖包的安装 6 //检查gcc-c++ 、ncurses-devel是否安装,如果没有安装,先用yum进行安装 7 8 编译安装cmake工具 9 cd /usr/local/src 10 tar xf cmake-3.6.2.tar.gz 11 cd cmake-3.6.2 12 ./bootstrap --prefix=/usr/local/cmake 13 make 14 make install #如果前面没有指定安装目录,则默认安装到/usr/local/bin/cmake 15 16 建立mysql组和用户,并将mysql用户添加到mysql组 17 groupadd mysql 18 useradd -g mysql mysql 19 创建mysql数据文件存放的目录 20 mkdir /mydata 21 chown mysql:mysql /mydata 22 chmod o= /mydata #设置其他人没有任何权限 23 24 编译安装mysql 25 cd /usr/local/src 26 tar xf mysql-5.7.16.tar.gz 27 cd mysql-5.7.16 28 /usr/local/cmake/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata -DWITH_BOOST=/usr/local/src -DSYSCONFDIR=/etc -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled 29 make && make install 30 31 更改mysql安装目录的属主属组并添加mysql环境变量 32 chown -R mysql:mysql /usr/local/mysql 33 vim /etc/profile.d/mysql.sh 34 文件内容是: 35 export PATH=$PATH:/usr/local/mysql/bin 36 执行命令: 37 bash #让新的PATH变量生效 38 39 加入服务列表并设置为开机自启 40 cd /usr/local/mysql/support-files 41 cp mysql.server /etc/init.d/mysqld 42 chmod +x /etc/init.d/mysqld 43 chkconfig mysqld on 44 45 修改mysql的配置文件 46 cat /etc/my.cnf 47 48 [mysql] 49 socket=/tmp/mysql.sock 50 51 [mysqld] 52 datadir=/mydata 53 socket=/tmp/mysql.sock 54 user=mysql 55 symbolic-links=0 56 57 [mysqld_safe] 58 log-error=/var/log/mysqld.log 59 pid-file=/mydata/mysqld.pid 60 61 初始化mysql 62 mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mydata 63 说明: 64 ##“-–initialize”会生成一个随机密码(~/.mysql_secret),而”–initialize-insecure”不会生成密码 ##user表示指定用户 ##basedir表示mysql的安装路径,datadir表示数据库文件存放路径 65 66 启动mysql服务 67 # service mysqld start 68 查看MySQL服务的进程和端口 69 # ps -ef | grep mysqld 70 root 22306 1 0 12:51 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mydata --pid-file=/mydata/web1.deng.com.pid 71 mysql 22480 22306 12 12:51 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mydata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/mydata/web1.deng.com.pid --socket=/tmp/mysql.sock 72 73 # netstat -an | grep :3306 74 tcp 0 0 :::3306 :::* LISTEN 75 76 初始化MySQL数据库的root用户密码 77 # mysql_secure_installation 78 79 Securing the MySQL server deployment. 80 81 Connecting to MySQL using a blank password. 82 83 VALIDATE PASSWORD PLUGIN can be used to test passwords 84 and improve security. It checks the strength of password 85 and allows the users to set only those passwords which are 86 secure enough. Would you like to setup VALIDATE PASSWORD plugin? 87 88 Press y|Y for Yes, any other key for No: y #需要修改密码,所以输入y 89 90 There are three levels of password validation policy: 91 92 LOW Length >= 8 93 MEDIUM Length >= 8, numeric, mixed case, and special characters 94 STRONG Length >= 8, numeric, mixed case, special characters and dictionary file 95 96 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 #设置密码复杂度为强 97 Please set the password for root here. 98 99 New password: 100 101 Re-enter new password: #输入2次新密码 102 103 Estimated strength of the password: 100 104 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y 105 By default, a MySQL installation has an anonymous user, 106 allowing anyone to log into MySQL without having to have 107 a user account created for them. This is intended only for 108 testing, and to make the installation go a bit smoother. 109 You should remove them before moving into a production 110 environment. 111 112 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y #删除匿名用户 113 Success. 114 115 116 Normally, root should only be allowed to connect from 117 ‘localhost‘. This ensures that someone cannot guess at 118 the root password from the network. 119 120 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #禁止root远程登录 121 122 ... skipping. 123 By default, MySQL comes with a database named ‘test‘ that 124 anyone can access. This is also intended only for testing, 125 and should be removed before moving into a production 126 environment. 127 128 129 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y #删除测试数据库 130 - Dropping test database... 131 Success. 132 133 - Removing privileges on test database... 134 Success. 135 136 Reloading the privilege tables will ensure that all changes 137 made so far will take effect immediately. 138 139 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #重新加载权限表 140 Success. 141 142 All done! 143 144 将MySQL数据库的动态链接库共享至系统链接库 145 vim /etc/ld.so.conf.d/mysql.conf 146 文件内容是: 147 /usr/local/mysql/lib 148 149 ldconfig -v 让系统重新读取库文件 150 151 测试登陆MySQL数据库 152 # mysql -uroot -p 153 Enter password: #输入刚才设置的新密码 154 Welcome to the MySQL monitor. Commands end with ; or g. 155 Your MySQL connection id is 5 156 Server version: 5.7.14 Source distribution 157 158 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 159 160 Oracle is a registered trademark of Oracle Corporation and/or its 161 affiliates. Other names may be trademarks of their respective 162 owners. 163 164 Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement. 165 166 mysql> show databases; 167 +--------------------+ 168 | Database | 169 +--------------------+ 170 | information_schema | 171 | mysql | 172 | performance_schema | 173 | sys | 174 +--------------------+ 175 4 rows in set (0.00 sec) 176 177 mysql> exit 178 Bye

cmake-3.6.2.tar.gz

链接:https://pan.baidu.com/s/1wR0j_JsiZy_Y2aqXRXvzIg
提取码:phx9
boost_1_59_0.tar.gz

链接:https://pan.baidu.com/s/1wfZCkQ1O4qvSFhlRqh-lmg
提取码:fgsv
apr-util-1.5.4.tar.bz2

链接:https://pan.baidu.com/s/1Uf4RI_AlhHqWFFRzIG9tyA
提取码:otp1

apr-1.5.2.tar.bz2

链接:https://pan.baidu.com/s/1GZvJtxmJCGPdqO32Kk8GpQ
提取码:iqxm

mysql-5.7.16.tar.gz

链接:https://pan.baidu.com/s/1cFnpfi4KOpXzI1_tf6G9Jw
提取码:l6mh















以上是关于Linux下MySQL安装的主要内容,如果未能解决你的问题,请参考以下文章

linux下源代码搭建php环境之mysql

mysql查看版本的四种方法

Linux下基于源代码方式安装MySQL 5.6

linux下安装mysql

Linux平台下安装MySQL

下载mysql5.6源码在linux下安装