本文共 14271 字,大约阅读时间需要 47 分钟。
目录
http://downloads.mysql.com/archives.php
安装环境 ubuntu 8.10
sudo apt-get install mysql-server
New password for the MySQL "root" user
┌──────────────────────┤ Configuring mysql-server-5.0 ├─────────────────────┐ │ While not mandatory, it is highly recommended that you set a password for the MySQL administrative "root" user. │ │ │ │ If that field is left blank, the password will not be changed. │ │ │ │ New password for the MySQL "root" user: │ │ │ │ ****____________________________________________________________________________________________________________ │ │ │ ││ │ │ └─────────────────────────────────────────────────────────────┘
Repeat password for the MySQL "root" user
┌───┤ Configuring mysql-server-5.0 ├────┐ │ │ │ │ │ Repeat password for the MySQL "root" user: │ │ │ │ ****_______________________________________ │ │ │ ││ │ │ └─────────────────────────┘
create database
create database example;mysql> SHOW GRANTS;+----------------------------------------------------------------------------------------------------------------------------------------+| Grants for root@localhost |+----------------------------------------------------------------------------------------------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*C6325DAF39AE6CC34E960D3C65F1398FE467E1D0' WITH GRANT OPTION |+----------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)GRANT ALL PRIVILEGES ON example.* TO 'dbuser'@'localhost' IDENTIFIED BY '******' WITH GRANT OPTION;FLUSH PRIVILEGES;./mysql -udbuser -pEnter password:./mysql -udbuser -p example < /tmp/example_china_copy.sql./mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.0.45 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> use example;Database changedmysql> show tables;
配置文件样本
debian:~# ls /usr/share/doc/mysql-server-5.0/examples/my-huge.cnf.gz my-innodb-heavy-4G.cnf.gz my-large.cnf.gz my-medium.cnf.gz my-small.cnf ndb_mgmd.cnf
./configure \--prefix=/usr/local/$MYSQL_DIR \--enable-assembler \--enable-local-infile \--with-charset=utf8 \--with-collation=utf8_general_ci \--with-extra-charsets=none \--with-openssl \--with-pthread \--with-unix-socket-path=/var/lib/mysql/mysql.sock \--with-mysqld-user=mysql \--with-mysqld-ldflags \--with-client-ldflags \--with-comment \--with-big-tables \--without-ndb-debug \--without-docs \--without-debug \--without-benchmake && make install
/usr/local/$MYSQL_DIR/bin/mysql_install_db
other option
--without-isam--without-innodb--without-ndbcluster--without-blackhole--without-ibmdb2i--without-federated--without-example--without-comment--localstatedir=/usr/local/mysql/data
shell> groupadd mysqlshell> useradd -r -g mysql mysqlshell> cd /usr/localshell> tar zxvf /path/to/mysql-VERSION-OS.tar.gzshell> ln -s full-path-to-mysql-VERSION-OS mysqlshell> cd mysqlshell> chown -R mysql .shell> chgrp -R mysql .shell> scripts/mysql_install_db --user=mysqlshell> chown -R root .shell> chown -R mysql data# Next command is optionalshell> cp support-files/my-medium.cnf /etc/my.cnfshell> bin/mysqld_safe --user=mysql &# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server
install core database
[root@test mysql]# ./scripts/mysql_install_dbInstalling MySQL system tables...100428 23:16:20 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.OKFilling help tables...100428 23:16:20 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:./bin/mysqladmin -u root password 'new-password'./bin/mysqladmin -u root -h db.example.com password 'new-password'Alternatively you can run:./bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd . ; ./bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd ./mysql-test ; perl mysql-test-run.plPlease report any problems with the ./bin/mysqlbug script!
set root's password
[root@test mysql]# cp support-files/mysql.server /etc/init.d/mysqld[root@test mysql]# /etc/init.d/mysqld startStarting MySQL. [ OK ][root@test mysql]# ./bin/mysqladmin -u root password 'chen'[root@test mysql]# ./bin/mysqladmin -u root -h db.example.com password 'chen'
test
[root@test mysql]# ./bin/mysql -uroot -pchenWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.45 MySQL Community Server (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
sudo apt-get install libaio1sudo groupadd mysqlsudo useradd -r -g mysql mysqlsudo dpkg -i mysql-5.5.21-debian6.0-i686.debcd /opt/mysql/sudo chown -R mysql .sudo chgrp -R mysql .cd server-5.5/sudo support-files/binary-configuresudo chown -R mysql data# Next command is optionalshell> cp support-files/my-medium.cnf /etc/my.cnfshell> bin/mysqld_safe --user=mysql &# Next command is optionalsudo cp support-files/mysql.server /etc/init.d/mysql
准备下面的软件包
# ls -1MySQL-client-5.5.25-1.el6.x86_64.rpmMySQL-devel-5.5.25-1.el6.x86_64.rpmMySQL-server-5.5.25-1.el6.x86_64.rpmMySQL-shared-5.5.25-1.el6.x86_64.rpmMySQL-shared-compat-5.5.25-1.el6.x86_64.rpm
使用 yum 本地安装 rpm, yum 可以帮你解决依赖于冲突
# yum localinstall MySQL-*
# /etc/init.d/mysql startStarting MySQL... SUCCESS!# /usr/bin/mysqladmin -u root password 'tUG26WSslP30bkbwtMhn'
$ sudo apt-get install mysql-admin
运行mysql-admin
/usr/bin/mysql-admin
运行 mysql-query-browser
mysql-query-browser --query="SELECT * FROM users"
http://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/linux-installation-yum-repo.html
yum localinstall http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
安装MySQL Server
yum install mysql-serverchkconfig mysqld onservice mysqld start
修改root密码
mysqladmin -u root password 'new-password'
安全设置向导
/usr/bin/mysql_secure_installation
yum localinstall -y https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpmyum install mysql-server -ysystemctl enable mysqldsystemctl start mysqldcp /etc/my.cnf{,.original}cat >> /etc/security/limits.d/20-nofile.conf <> /etc/my.cnf.d/default.cnf <
MySQL 5.7 会随机分配一个密码给用户
grep "A temporary password" /var/log/mysqld.log
登陆后修改密码
ALTER USER root@localhost identified by 'MQiEge1ikst7S_6tlXzBOmt_4b';ALTER USER root@localhost PASSWORD EXPIRE NEVER;
安装
brew install mysql
启动
brew services start mysql
iptables
iptables -A INPUT -i eth0 -p tcp -s xxx.xxx.xxx.xxx --dport 3306 -j ACCEPT
$ sudo cat /proc/`pidof mysqld`/limitsLimit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 10485760 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 62662 62662 processes Max open files 20480 20480 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 62662 62662 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us
#!/bin/shsystemctl stop mysqldbtrfs subvolume create /srv/@mysqlbtrfs subvolume list /srv/UUID=$(blkid | grep btrfs | sed -e 's/.*UUID="\([^"]*\)".*/\1/')# UUID=786f570d-fe5c-4d5f-832a-c1b0963dd4e6 /srv btrfs defaults 1 1cat << EOF >> /etc/fstabUUID=${UUID} /var/lib/mysql btrfs noatime,nodiratime,subvol=@mysql 0 2EOFmkdir /tmp/mysqlmv /var/lib/mysql/* /tmp/mysql/mount /var/lib/mysql/chown mysql:mysql /var/lib/mysqlmv /tmp/mysql/* /var/lib/mysql/systemctl start mysqld
brew install mysql
启动
brew services start mysql