lundi 28 mars 2016

scripting mysql 5.7 install from zip

MySQL added a new 'feature' in 5.7 which does the following when installing from their 300 MB + zip file on windows :

  • Generates a random root password
  • Does not echo the password to any file
  • Echo's the password as part of an error message in Windows Event log
  • Expires root passwords by default after a very short period.

I have written an application in c# which downloads the current zip, expands it, uses their new command to initialize the data directory ( 5.7.7+ ), however I am stuck at this whole random root password thing.

MySQL Password in Event Viewer

From the mysql log file (mysql.err)

2016-03-28T12:33:46.525571Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2016-03-28T12:33:46.525571Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.

The other errors in the event log :

Failed to open log (file '2016-03-28T12:33:48.852814Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.', errno 13)For more information, see Help and Support Center at http://www.mysql.com.

Could not open log fileFor more information, see Help and Support Center at http://www.mysql.com.

Failed to open log (file '2016-03-28T12:33:48.500082Z 0 [Warning] InnoDB: New log files created, LSN=45790', errno 13)For more information, see Help and Support Center at http://www.mysql.com.

Could not open log fileFor more information, see Help and Support Center at http://www.mysql.com.

And the warnings in the event log :

InnoDB: New log files created, LSN=45790For more information, see Help and Support Center at http://www.mysql.com.

InnoDB: Creating foreign key constraint system tables.For more information, see Help and Support Center at http://www.mysql.com.

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: 5243756b-f4e1-11e5-bf9f-c8600006aa50.For more information, see Help and Support Center at http://www.mysql.com.

Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.For more information, see Help and Support Center at http://www.mysql.com.

After some time, the mysql.err file reports the following (lagged):

2016-03-28T12:33:46.525571Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-03-28T12:33:46.525571Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-03-28T12:51:11.085041Z 0 [ERROR] --verbose is for use with --help; did you mean --log-error-verbosity?
2016-03-28T12:51:11.085041Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2016-03-28T12:51:11.085041Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2016-03-28T12:51:11.085041Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2016-03-28T12:51:11.085540Z 0 [Note] bin\mysqld (mysqld 5.7.11-log) starting as process 4924 ...
2016-03-28T12:51:11.226559Z 0 [ERROR] Plugin keyring_file reported: 'keyring_file initialization failure. Please check if the keyring_file_data points to readable keyring file or keyring file can be created in the specified location. The keyring_file will stay unusable until correct path to the keyring file gets provided'
2016-03-28T12:51:11.230064Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2016-03-28T12:51:11.231065Z 0 [Note] InnoDB: Uses event mutexes
2016-03-28T12:51:11.231565Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier
2016-03-28T12:51:11.232559Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-03-28T12:51:11.234066Z 0 [Note] InnoDB: Number of pools: 1
2016-03-28T12:51:11.234565Z 0 [Note] InnoDB: Not using CPU crc32 instructions
2016-03-28T12:51:11.300490Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2016-03-28T12:51:11.313506Z 0 [Note] InnoDB: Completed initialization of buffer pool
2016-03-28T12:51:11.367971Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2016-03-28T12:51:11.558971Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2016-03-28T12:51:11.559971Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2016-03-28T12:51:11.769085Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB.
2016-03-28T12:51:11.778533Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2016-03-28T12:51:11.779533Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2016-03-28T12:51:11.780533Z 0 [Note] InnoDB: Waiting for purge to start
2016-03-28T12:51:11.832079Z 0 [Note] InnoDB: 5.7.11 started; log sequence number 2494086
2016-03-28T12:51:11.833581Z 0 [Note] InnoDB: Loading buffer pool(s) from d:\server\data\mysql\ib_buffer_pool
2016-03-28T12:51:11.833581Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqld: File '2016-03-28T12:33:48.992984Z 1 [Note] A temporary password is generated for root@localhost: aVV,7T)iiFug' not found (Errcode: 13 - Permission denied)
2016-03-28T12:51:11.851582Z 0 [ERROR] Failed to open log (file '2016-03-28T12:33:48.992984Z 1 [Note] A temporary password is generated for root@localhost: aVV,7T)iiFug', errno 13)
2016-03-28T12:51:11.853082Z 0 [ERROR] Could not open log file
2016-03-28T12:51:11.853583Z 0 [ERROR] Can't init tc log
2016-03-28T12:51:11.854083Z 0 [ERROR] Aborting

2016-03-28T12:51:11.854583Z 0 [Note] Binlog end
2016-03-28T12:51:11.855084Z 0 [Note] Shutting down plugin 'ngram'
2016-03-28T12:51:11.855583Z 0 [Note] Shutting down plugin 'partition'
2016-03-28T12:51:11.856083Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2016-03-28T12:51:11.857083Z 0 [Note] Shutting down plugin 'ARCHIVE'
2016-03-28T12:51:11.857583Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2016-03-28T12:51:11.859086Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2016-03-28T12:51:11.860083Z 0 [Note] Shutting down plugin 'MyISAM'
2016-03-28T12:51:11.860585Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2016-03-28T12:51:11.862584Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2016-03-28T12:51:11.863588Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2016-03-28T12:51:11.864584Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2016-03-28T12:51:11.865584Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2016-03-28T12:51:11.866585Z 0 [Note] InnoDB: Buffer pool(s) load completed at 160328  8:51:11
2016-03-28T12:51:11.866585Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2016-03-28T12:51:11.868585Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2016-03-28T12:51:11.869588Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2016-03-28T12:51:11.870585Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2016-03-28T12:51:11.872085Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2016-03-28T12:51:11.872585Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2016-03-28T12:51:11.873613Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2016-03-28T12:51:11.874110Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2016-03-28T12:51:11.875086Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2016-03-28T12:51:11.875586Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2016-03-28T12:51:11.876086Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2016-03-28T12:51:11.876586Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2016-03-28T12:51:11.877087Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2016-03-28T12:51:11.878086Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2016-03-28T12:51:11.878586Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2016-03-28T12:51:11.879087Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2016-03-28T12:51:11.879587Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2016-03-28T12:51:11.880087Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2016-03-28T12:51:11.880587Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2016-03-28T12:51:11.881586Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2016-03-28T12:51:11.882087Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2016-03-28T12:51:11.882587Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2016-03-28T12:51:11.883087Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2016-03-28T12:51:11.883587Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2016-03-28T12:51:11.884087Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2016-03-28T12:51:11.884587Z 0 [Note] Shutting down plugin 'InnoDB'
2016-03-28T12:51:11.885587Z 0 [Note] InnoDB: FTS optimize thread exiting.
2016-03-28T12:51:11.886102Z 0 [Note] InnoDB: Starting shutdown...
2016-03-28T12:51:11.987153Z 0 [Note] InnoDB: Dumping buffer pool(s) to d:\server\data\mysql\ib_buffer_pool
2016-03-28T12:51:12.000601Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 160328  8:51:12
2016-03-28T12:51:13.328404Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2494105
2016-03-28T12:51:13.329404Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2016-03-28T12:51:13.330405Z 0 [Note] Shutting down plugin 'MEMORY'
2016-03-28T12:51:13.330905Z 0 [Note] Shutting down plugin 'CSV'
2016-03-28T12:51:13.331405Z 0 [Note] Shutting down plugin 'sha256_password'
2016-03-28T12:51:13.331904Z 0 [Note] Shutting down plugin 'mysql_native_password'
2016-03-28T12:51:13.332405Z 0 [Note] Shutting down plugin 'keyring_file'
2016-03-28T12:51:13.334904Z 0 [Note] Shutting down plugin 'binlog'
2016-03-28T12:51:13.342906Z 0 [Note] bin\mysqld: Shutdown complete

Take a particular interest where the password eventually shows up, and for the time it claims it was for. It claims 2016-03-28T12:33:48.992984Z but it is inserted just after 2016-03-28T12:51:11.833581Z. Even if I did write my installer to account for a 20 minute delay for the passwords mystical appearance, and handled the parsing -- or looped through a seemingly random number of mysql events (in the picture is 9, but seems to vary between 8 and 40 event entries so far on each test it's kind of random), but even if I did decide to account for this ridiculous mess, that would mean the user would need to wait for X random period of time prior to being able to access the database from a fresh install.

I have looked into passing other parameters such as --skip-random-passwords, but that only resulted in 'unknown parameter'.

How can I reliably script an install from zip (aka what parameters can i pass to mysqld or set in the ini file) to prevent this horrible 'feature' from breaking it -- or to at worst, get the password during script processing in a reasonable manner ?

Update

Switched --initialize to --initialize-insecure, but still getting this message

Server MySQL: File '2016-03-28T13:39:21.469620Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.' not found (Errcode: 13 - Permission denied)

... which is preventing proper startup. It looks like it thinks 2016-03-28T13:39:21.469620Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. is the filename to log to somehow, so here is the my.ini file :

# For advice on how to change settings please see
# http://ift.tt/ZQDJna

[mysqld]
server_id = 1

explicit_defaults_for_timestamp=1
# 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 = myserver-bin
log_error = d:/server/var/log/mysql_log

# These are commonly set, remove the # and set as required.
basedir = d:/server
datadir =  d:/server/data/mysql
plugin-dir = d:/server/bin/modules/mysql
port = 3306

# Enable general logging
general-log = 0
general-log-file = d:/server/var/log/mysql_log

# Enable slow query logging
slow_query_log = 0
log_queries_not_using_indexes = 0
slow_query_log_file = d:/server/var/log/mysql_slow_log
long_query_time = 20

# Define server process location
pid_file = d:/server/var/run/mysql.pid

# 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
# ssl-ca=$DIR/ca.pem
ssl-cert=d:/server/var/certificates/localhost.crt
ssl-key=d:/server/var/certificates/localhost.key




Generating a random permutation of a list

I am trying to make a "terminal hack" game but I am stuck at somewhere.
This is what my code currently looks:

import random

candidateWords = ['AETHER', 'BADGED', 'BALDER', 'BANDED', 'BANTER', 'BARBER'] #etc, etc

def wordlist(word):
    for index, item in enumerate(random.sample(list(candidateWords), 8)):
        print(index, ") ", item,  sep='')           
one = random.choice(candidateWords)
print(one)  

print("Welcome to the Guess-The-Word Game.\nThe Password is one of these words:")

I'm trying to make a list of 8 words and enumerate it to give a number for each word. Then, from the 8 words, I need to randomly choose a word to be the answer but I don't know how.

I want to use random.sample() and random.choice().




how to get random amount of details from a list or var in c#

I'm reading result from an json file inside the local project.it returns more than 4000 result.I want to get only random number of results (between 500- 1000) from that result.

 var finalResultz = finalResults("All","All","All");//step one

in here it returns more than 4000 results.then I put into a list like this.

List<Results> searchOne = new List<Results>();//step two
            foreach(var itms in finalResultz)
            {
                searchOne.Add(new Results 
                {
                    resultDestination = returnRegionName(itms.areaDestination),
                    mainImageurl = itms.testingImageUrl
                });
            }


            ViewBag.requested = searchOne;

but I want to get only the results like I said.I want to resize the count in step one or in step two.how can I do that.hope your help.




How to generate a 'random signal' in pycharm?

I am trying to generate a random signal in Python. I want the amplitude to range between -10 volts to +10 volts and the length of signal should be 5 sec. How can I vary the time constant and compare?




Randomised Image is displayed more than once

Functionality:

Brand image is randomised and is displayed within the container list. Each of the randomised brand image needs to be only displayed once.

What has been done:

Firstly, I have created an array of image files as var ImageArray=["","","",....]. Secondly, I have created a randomised method as var random_BrandIndex = Math.floor(Math.random() * BrandNameArray.length); and lastly, I created a for loop that will allow the image to populate the table created within the html body.

I have attached the code for your perusal:

//Brand Array
var BrandNameArray = ["lib/img/PAGE03/Brands/Ads.png", "lib/img/PAGE03/Brands/AEO.png", "lib/img/PAGE03/Brands/AO.png", "lib/img/PAGE03/Brands/Beauty.png", "lib/img/PAGE03/Brands/Be.png", "lib/img/PAGE03/Brands/DS.png", "lib/img/PAGE03/Brands/Cch.png", "lib/img/PAGE03/Brands/Coton.png", "lib/img/PAGE03/Brands/Dwel.png", "lib/img/PAGE03/Brands/esBr.png", "lib/img/PAGE03/Brands/Et.png", "lib/img/PAGE03/Brands/E.png"];

$(function() {
  //Auto populate into brand container once randomised for each Brand image
  for (i = 0; i < $('#list').find('img').length; i++) {
    //To Set random Brand
    var random_BrandIndex = Math.floor(Math.random() * BrandNameArray.length);
    //Assign Variable to generate random Brands
    var Brand = BrandNameArray[random_BrandIndex];
    $('#Brand_' + (i + 1)).attr('src', Brand);
    $('#Brand_' + (i + 1)).show();
    console.log(Brand);
  }
});
.Container {
  position: absolute;
  top: 300px;
  left: 300px;
  height: 600px;
  width: 1250px;
  overflow-y: scroll;
}
.innerScroll {
  position: relative;
  width: 1250px;
  height: 600px;
  font-size: 25px;
  color: #8d8989 !important;
  overflow: scroll;
}
<div class="Container">
  <div id="list" class="innerScroll">
    <!--1st Row-->
    <img id="Brand_1" style="width:284px; height:140px; top:0px; left:0px; border:0px; outline:0px" onclick="selectBrand('1');">
    <img id="Brand_2" style="width:284px; height:140px; top:0px; left:330px; border:0px;" onclick="selectBrand('2');">
    <img id="Brand_3" style="width:284px; height:140px; top:0px; left:650px; border:0px;" onclick="selectBrand('3');">
    <img id="Brand_4" style="width:284px; height:140px; top:0px; left:965px; border:0px;" onclick="selectBrand('4');">

    <!--2nd Row-->
    <img id="Brand_5" style="width:284px; height:140px; top:140px; left:0px; border:0px;" onclick="selectBrand('5');">
    <img id="Brand_6" style="width:284px; height:140px; top:140px; left:330px; border:0px;" onclick="selectBrand('6');">
    <img id="Brand_7" style="width:284px; height:140px; top:140px; left:650px; border:0px;" onclick="selectBrand('7');">
    <img id="Brand_8" style="width:284px; height:140px; top:140px; left:965px; border:0px;" onclick="selectBrand('8');">

    <!--3rd Row-->
    <img id="Brand_9" style="width:284px; height:140px; top:280px; left:0px; border:0px;" onclick="selectBrand('9');">
    <img id="Brand_10" style="width:284px; height:140px; top:280px; left:330px; border:0px;" onclick="selectBrand('10');">
    <img id="Brand_11" style="width:284px; height:140px; top:280px; left:650px; border:0px;" onclick="selectBrand('11');">
    <img id="Brand_12" style="width:284px; height:140px; top:280px; left:965px; border:0px;" onclick="selectBrand('12');">

    <!--4th Row-->
    <img id="Brand_09" style="width:284px; height:140px; top:280px; left:0px; border:0px;" onclick="selectBrand('9');">
    <img id="Brand_10" style="width:284px; height:140px; top:280px; left:330px; border:0px;" onclick="selectBrand('10');">
    <img id="Brand_11" style="width:284px; height:140px; top:280px; left:650px; border:0px;" onclick="selectBrand('11');">
    <img id="Brand_12" style="width:284px; height:140px; top:280px; left:965px; border:0px;" onclick="selectBrand('12');">.....(more rows of images)...
  </div>
</div>

Issue:

At this point in time, the randomised images are displaying. However, some of the images displayed are displayed more than once.

Therefore, How is it possible for the randomised image to be only displayed once within the <div id ="list">?

please help. your help is much much appreciated.




How can I get a random number of element from list

I am writing to You with small problem. I am writing small application in C#.NET MVC5, and I have one question, how can I get a few random items from List?

My code:

public ActionResult ProductsList()
{
    List<Product> products = productRepo.GetProduct().ToList();
    return PartialView(products);
}

This method return full list, how can I do it correctly?




How can I make moves between neighbors pictures? C# puzzle

Good morning I have problem, with my game. How can I make moves between neighbors pictures? We have an problem with moving of parts of pictures. It must move only when part of picture and the white field are next to each. Here are

Form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PuzzleN
{
    public partial class Form1 : Form
    {
        private Field game;
        private PictureBox[,] picture;

        public Form1()
        {
            InitializeComponent();
            game = new Field();
            initPictures();
        }

        private void initPictures()//set pictures on positions in boxes
        {
            picture = new PictureBox[4, 4];
            picture[0, 0] = pictureBox0;
            picture[0, 1] = pictureBox1;
            picture[0, 2] = pictureBox2;
            picture[0, 3] = pictureBox3;
            picture[1, 0] = pictureBox4;
            picture[1, 1] = pictureBox5;
            picture[1, 2] = pictureBox6;
            picture[1, 3] = pictureBox7;
            picture[2, 0] = pictureBox8;
            picture[2, 1] = pictureBox9;
            picture[2, 2] = pictureBox10;
            picture[2, 3] = pictureBox11;
            picture[3, 0] = pictureBox12;
            picture[3, 1] = pictureBox13;
            picture[3, 2] = pictureBox14;
            picture[3, 3] = pictureBox15;
            UpdatePictures();
        }

        private void UpdatePictures()
        {
            for (int i = 0; i &lt; 4; i++)
            {
                for (int j = 0; j &lt; 4; j++)
                {
                    picture[i, j].Image = game.getTile(i, j).getImage();
                }
            }
        }

        private void pict1_Click(object sender, EventArgs e)
        {

        }

        private void startGameToolStripMenuItem_Click(object sender, EventArgs e)//generate random positions of parts of picture
        {
            int p;
            Random gen = new Random();
            int nc;
            for (p = 0; p &lt; 2000; p++)
            {
                nc = gen.Next(0, 16);
                if (game.isMovePosible(nc))
                {
                    //Console.Write(&quot;ok&quot;);s000fff
                      game.moveTile(nc);
                }
            }
            UpdatePictures();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        //info about author
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormAbout formAbout = new FormAbout();
            formAbout.ShowDialog();
        }

        //restart game
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Application.Restart();
        }

        //close game
        private void exitGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void pictureBox0_Click(object sender, EventArgs e)
        {

        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}

We have method for randomize position of tiles in class Tile but it must change onclick by mouse on box. How to do?